1
- # Node.js Datadog API Client
1
+ # Node.js Datadog API Client V2
2
2
3
3
[ ![ License] ( https://img.shields.io/badge/License-Apache%202.0-blue.svg )] ( https://opensource.org/licenses/Apache-2.0 )
4
4
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 .
6
6
7
7
## How to install
8
8
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}/ ` .
18
10
19
11
## Getting Started
20
12
21
13
Here's an example getting a monitor:
22
14
23
15
``` typescript
24
- import { client , v1 } from ' @datadog/datadog-api-client' ;
16
+ import { v1 } from ' @datadog/datadog-api-client-monitors ' ;
25
17
26
- const configuration = client .createConfiguration ();
27
- const apiInstance = new v1 .MonitorsApi (configuration );
18
+ const apiInstance = new v1 .MonitorsApiV1 ();
28
19
29
- let params: v1 .MonitorsApiGetMonitorRequest = {
20
+ let params: v1 .MonitorsApiGetMonitorRequest = {
30
21
// number | The ID of the monitor
31
22
monitorId: 1 ,
32
23
};
@@ -43,7 +34,8 @@ By default the library will use the `DD_API_KEY` and `DD_APP_KEY` environment va
43
34
To provide your own set of credentials, you need to set the appropriate keys on the configuration:
44
35
45
36
``` 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' ;
47
39
48
40
const configurationOpts = {
49
41
authMethods: {
@@ -52,7 +44,8 @@ const configurationOpts = {
52
44
},
53
45
};
54
46
55
- const configuration = client .createConfiguration (configurationOpts );
47
+ const configuration = createConfiguration (configurationOpts );
48
+ const apiInstance = new v1 .MonitorsApiV1 (configuration );
56
49
```
57
50
58
51
### Unstable Endpoints
@@ -70,9 +63,9 @@ where `<operationName>` is the name of the method used to interact with that end
70
63
When talking to a different server, like the ` eu ` instance, change the server variables:
71
64
72
65
``` typescript
73
- import { client } from ' @datadog/datadog-api-client' ;
66
+ import { createConfiguration } from ' @datadog/datadog-api-client' ;
74
67
75
- const configuration = client . createConfiguration ();
68
+ const configuration = createConfiguration ();
76
69
77
70
configuration .setServerVariables ({
78
71
site: " datadoghq.eu"
@@ -85,40 +78,40 @@ If you want to disable GZIP compressed responses, set the `compress` flag
85
78
on your configuration options:
86
79
87
80
``` typescript
88
- import { client } from ' @datadog/datadog-api-client' ;
81
+ import { createConfiguration } from ' @datadog/datadog-api-client' ;
89
82
const configurationOpts = {
90
83
httpConfig: {
91
84
compress: false
92
85
},
93
86
};
94
87
95
- const configuration = client . createConfiguration (configurationOpts );
88
+ const configuration = createConfiguration (configurationOpts );
96
89
```
97
90
98
91
### Enable requests logging
99
92
100
93
If you want to enable requests logging, set the ` debug ` flag on your configuration object:
101
94
102
95
``` typescript
103
- import { client } from ' @datadog/datadog-api-client' ;
96
+ import { createConfiguration } from ' @datadog/datadog-api-client' ;
104
97
const configurationOpts = {
105
98
debug: true
106
99
};
107
100
108
- const configuration = client . createConfiguration (configurationOpts );
101
+ const configuration = createConfiguration (configurationOpts );
109
102
```
110
103
111
104
### Enable retry
112
105
113
106
To enable the client to retry when rate limited (status 429) or status 500 and above:
114
107
115
108
``` typescript
116
- import { client } from ' @datadog/datadog-api-client' ;
109
+ import { createConfiguration } from ' @datadog/datadog-api-client' ;
117
110
const configurationOpts = {
118
111
enableRetry: true
119
112
};
120
113
121
- const configuration = client . createConfiguration (configurationOpts );
114
+ const configuration = createConfiguration (configurationOpts );
122
115
```
123
116
The interval between 2 retry attempts will be the value of the x-ratelimit-reset response header when available. If not, it will be :
124
117
@@ -139,7 +132,9 @@ controller, for example the one implemented by
139
132
then pass the `signal method to the HTTP configuration options:
140
133
141
134
``` 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
+
143
138
import AbortController from ' abort-controller' ;
144
139
145
140
const controller = new AbortController ();
@@ -153,7 +148,7 @@ const configurationOpts = {
153
148
},
154
149
};
155
150
156
- const configuration = client . createConfiguration (configurationOpts );
151
+ const configuration = createConfiguration (configurationOpts );
157
152
158
153
const apiInstance = new v1 .MonitorsApi (configuration );
159
154
apiInstance .listMonitors ().then ((data : v1 .Monitor []) => {
@@ -167,10 +162,11 @@ Several listing operations have a pagination method to help consume all the item
167
162
For example, to retrieve all your incidents:
168
163
169
164
``` 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" ;
171
167
172
168
async function main() {
173
- const configuration = client . createConfiguration ();
169
+ const configuration = createConfiguration ();
174
170
configuration .unstableOperations [" v2.listIncidents" ] = true ;
175
171
const apiInstance = new v2 .IncidentsApi (configuration );
176
172
@@ -191,13 +187,14 @@ For example, using `zstd.ts` package:
191
187
192
188
``` typescript
193
189
import { 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" ;
195
192
196
193
async function main() {
197
194
const configurationOpts = {
198
195
zstdCompressorCallback : (body : string ) => compressSync ({input: Buffer .from (body , " utf8" )})
199
196
}
200
- const configuration = client . createConfiguration (configurationOpts );
197
+ const configuration = createConfiguration (configurationOpts );
201
198
const apiInstance = new v2 .MetricsApi (configuration );
202
199
const params: v2 .MetricsApiSubmitMetricsRequest = {
203
200
body: {
@@ -236,14 +233,16 @@ import pako from "pako";
236
233
import bufferFrom from " buffer-from" ;
237
234
import fetch from " node-fetch" ;
238
235
import { 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" ;
240
239
241
240
const proxyAgent = new HttpsProxyAgent (' http://127.0.0.11:3128' );
242
241
243
- class HttpLibraryWithProxy implements client . HttpLibrary {
242
+ class HttpLibraryWithProxy implements HttpLibrary {
244
243
public debug = false ;
245
244
246
- public send(request : client . RequestContext ): Promise <client . ResponseContext > {
245
+ public send(request : RequestContext ): Promise <ResponseContext > {
247
246
const method = request .getHttpMethod ().toString ();
248
247
let body = request .getBody ();
249
248
@@ -278,15 +277,15 @@ class HttpLibraryWithProxy implements client.HttpLibrary {
278
277
text : () => resp .text (),
279
278
binary : () => resp .buffer (),
280
279
};
281
- const response = new client . ResponseContext (resp .status , headers , body );
280
+ const response = new ResponseContext (resp .status , headers , body );
282
281
return response ;
283
282
});
284
283
285
284
return resultPromise ;
286
285
}
287
286
}
288
287
289
- const configuration = client . createConfiguration ({httpApi: new HttpLibraryWithProxy ()});
288
+ const configuration = createConfiguration ({httpApi: new HttpLibraryWithProxy ()});
290
289
const apiInstance = new v1 .DashboardsApi (configuration );
291
290
292
291
apiInstance
0 commit comments