1- # Node.js Datadog API Client
1+ # Node.js Datadog API Client V2
22
33[ ![ License] ( https://img.shields.io/badge/License-Apache%202.0-blue.svg )] ( https://opensource.org/licenses/Apache-2.0 )
44
5- This repository contains a Node.js API client for the [ Datadog API] ( https://docs.datadoghq.com/api/ ) .
5+ This repository contains the V2 rewrite of the TypeScript API client for the [ Datadog API] ( https://docs.datadoghq.com/api/ ) . The client is organized into logical API groups for better maintainability and usability .
66
77## How to install
88
9- The package is under [ @datadog/datadog-api-client ] ( https://www.npmjs.com/package/@datadog/datadog-api-client ) and can be installed through NPM or Yarn:
10-
11- ``` sh
12- # NPM
13- npm install @datadog/datadog-api-client
14-
15- # Yarn
16- yarn add @datadog/datadog-api-client
17- ```
9+ For detailed installation instructions, please refer to the README.md file in each client's directory under ` services/{client}/ ` .
1810
1911## Getting Started
2012
2113Here's an example getting a monitor:
2214
2315``` typescript
24- import { client , v1 } from ' @datadog/datadog-api-client' ;
16+ import { v1 } from ' @datadog/datadog-api-client-monitors ' ;
2517
26- const configuration = client .createConfiguration ();
27- const apiInstance = new v1 .MonitorsApi (configuration );
18+ const apiInstance = new v1 .MonitorsApiV1 ();
2819
29- let params: v1 .MonitorsApiGetMonitorRequest = {
20+ let params: v1 .MonitorsApiGetMonitorRequest = {
3021 // number | The ID of the monitor
3122 monitorId: 1 ,
3223};
@@ -43,7 +34,8 @@ By default the library will use the `DD_API_KEY` and `DD_APP_KEY` environment va
4334To provide your own set of credentials, you need to set the appropriate keys on the configuration:
4435
4536``` typescript
46- import { client } from ' @datadog/datadog-api-client' ;
37+ import { createConfiguration } from ' @datadog/datadog-api-client' ;
38+ import { v1 } from ' @datadog/datadog-api-client-monitors' ;
4739
4840const configurationOpts = {
4941 authMethods: {
@@ -52,7 +44,8 @@ const configurationOpts = {
5244 },
5345};
5446
55- const configuration = client .createConfiguration (configurationOpts );
47+ const configuration = createConfiguration (configurationOpts );
48+ const apiInstance = new v1 .MonitorsApiV1 (configuration );
5649```
5750
5851### Unstable Endpoints
@@ -70,9 +63,9 @@ where `<operationName>` is the name of the method used to interact with that end
7063When talking to a different server, like the ` eu ` instance, change the server variables:
7164
7265``` typescript
73- import { client } from ' @datadog/datadog-api-client' ;
66+ import { createConfiguration } from ' @datadog/datadog-api-client' ;
7467
75- const configuration = client . createConfiguration ();
68+ const configuration = createConfiguration ();
7669
7770configuration .setServerVariables ({
7871 site: " datadoghq.eu"
@@ -85,40 +78,40 @@ If you want to disable GZIP compressed responses, set the `compress` flag
8578on your configuration options:
8679
8780``` typescript
88- import { client } from ' @datadog/datadog-api-client' ;
81+ import { createConfiguration } from ' @datadog/datadog-api-client' ;
8982const configurationOpts = {
9083 httpConfig: {
9184 compress: false
9285 },
9386};
9487
95- const configuration = client . createConfiguration (configurationOpts );
88+ const configuration = createConfiguration (configurationOpts );
9689```
9790
9891### Enable requests logging
9992
10093If you want to enable requests logging, set the ` debug ` flag on your configuration object:
10194
10295``` typescript
103- import { client } from ' @datadog/datadog-api-client' ;
96+ import { createConfiguration } from ' @datadog/datadog-api-client' ;
10497const configurationOpts = {
10598 debug: true
10699};
107100
108- const configuration = client . createConfiguration (configurationOpts );
101+ const configuration = createConfiguration (configurationOpts );
109102```
110103
111104### Enable retry
112105
113106To enable the client to retry when rate limited (status 429) or status 500 and above:
114107
115108``` typescript
116- import { client } from ' @datadog/datadog-api-client' ;
109+ import { createConfiguration } from ' @datadog/datadog-api-client' ;
117110const configurationOpts = {
118111 enableRetry: true
119112};
120113
121- const configuration = client . createConfiguration (configurationOpts );
114+ const configuration = createConfiguration (configurationOpts );
122115```
123116The interval between 2 retry attempts will be the value of the x-ratelimit-reset response header when available. If not, it will be :
124117
@@ -139,7 +132,9 @@ controller, for example the one implemented by
139132then pass the `signal method to the HTTP configuration options:
140133
141134``` typescript
142- import { client , v1 } from ' @datadog/datadog-api-client' ;
135+ import { createConfiguration } from ' @datadog/datadog-api-client' ;
136+ import { v1 } from ' @datadog/datadog-api-client-monitors'
137+
143138import AbortController from ' abort-controller' ;
144139
145140const controller = new AbortController ();
@@ -153,7 +148,7 @@ const configurationOpts = {
153148 },
154149};
155150
156- const configuration = client . createConfiguration (configurationOpts );
151+ const configuration = createConfiguration (configurationOpts );
157152
158153const apiInstance = new v1 .MonitorsApi (configuration );
159154apiInstance .listMonitors ().then ((data : v1 .Monitor []) => {
@@ -167,10 +162,11 @@ Several listing operations have a pagination method to help consume all the item
167162For example, to retrieve all your incidents:
168163
169164``` typescript
170- import { client , v2 } from " @datadog/datadog-api-client" ;
165+ import { createConfiguration } from " @datadog/datadog-api-client" ;
166+ import { v2 } from " @datadog/datadog-api-client-incidents" ;
171167
172168async function main() {
173- const configuration = client . createConfiguration ();
169+ const configuration = createConfiguration ();
174170 configuration .unstableOperations [" v2.listIncidents" ] = true ;
175171 const apiInstance = new v2 .IncidentsApi (configuration );
176172
@@ -191,13 +187,14 @@ For example, using `zstd.ts` package:
191187
192188``` typescript
193189import { compressSync } from ' zstd.ts'
194- import { client , v2 } from " @datadog/datadog-api-client" ;
190+ import { createConfiguration } from " @datadog/datadog-api-client" ;
191+ import { v2 } from " @datadog/datadog-api-client-metrics" ;
195192
196193async function main() {
197194 const configurationOpts = {
198195 zstdCompressorCallback : (body : string ) => compressSync ({input: Buffer .from (body , " utf8" )})
199196 }
200- const configuration = client . createConfiguration (configurationOpts );
197+ const configuration = createConfiguration (configurationOpts );
201198 const apiInstance = new v2 .MetricsApi (configuration );
202199 const params: v2 .MetricsApiSubmitMetricsRequest = {
203200 body: {
@@ -236,14 +233,16 @@ import pako from "pako";
236233import bufferFrom from " buffer-from" ;
237234import fetch from " node-fetch" ;
238235import { HttpsProxyAgent } from " https-proxy-agent" ;
239- import { v1 , client } from " @datadog/datadog-api-client" ;
236+
237+ import { createConfiguration , ResponseContext , RequestContext , HttpLibrary } from " @datadog/datadog-api-client" ;
238+ import { v1 } from " @datadog/datadog-api-client" ;
240239
241240const proxyAgent = new HttpsProxyAgent (' http://127.0.0.11:3128' );
242241
243- class HttpLibraryWithProxy implements client . HttpLibrary {
242+ class HttpLibraryWithProxy implements HttpLibrary {
244243 public debug = false ;
245244
246- public send(request : client . RequestContext ): Promise <client . ResponseContext > {
245+ public send(request : RequestContext ): Promise <ResponseContext > {
247246 const method = request .getHttpMethod ().toString ();
248247 let body = request .getBody ();
249248
@@ -278,15 +277,15 @@ class HttpLibraryWithProxy implements client.HttpLibrary {
278277 text : () => resp .text (),
279278 binary : () => resp .buffer (),
280279 };
281- const response = new client . ResponseContext (resp .status , headers , body );
280+ const response = new ResponseContext (resp .status , headers , body );
282281 return response ;
283282 });
284283
285284 return resultPromise ;
286285 }
287286}
288287
289- const configuration = client . createConfiguration ({httpApi: new HttpLibraryWithProxy ()});
288+ const configuration = createConfiguration ({httpApi: new HttpLibraryWithProxy ()});
290289const apiInstance = new v1 .DashboardsApi (configuration );
291290
292291apiInstance
0 commit comments