Gathering detailed insights and metrics for @datadog/datadog-api-client
Gathering detailed insights and metrics for @datadog/datadog-api-client
Gathering detailed insights and metrics for @datadog/datadog-api-client
Gathering detailed insights and metrics for @datadog/datadog-api-client
Typescript client for the Datadog API
npm install @datadog/datadog-api-client
Typescript
Module System
Min. Node Version
v1.39.0
Updated on Jun 30, 2025
v1.38.0
Updated on Jun 24, 2025
v1.37.0
Updated on Jun 23, 2025
v1.36.0
Updated on Jun 16, 2025
services/tags/0.0.1-beta.1
Updated on Jun 05, 2025
services/spans_metrics/0.0.1-beta.1
Updated on Jun 05, 2025
TypeScript (89.05%)
Gherkin (9.76%)
Jinja (0.61%)
Python (0.52%)
JavaScript (0.03%)
Shell (0.02%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
89 Stars
1,912 Commits
17 Forks
522 Watchers
63 Branches
306 Contributors
Updated on Jul 03, 2025
Latest Version
1.39.0
Package Id
@datadog/datadog-api-client@1.39.0
Unpacked Size
17.93 MB
Size
1.85 MB
File Count
10,885
Published on
Jun 30, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
9
24
[!NOTE] The next major version iteration of
@datadog/datadog-api-client
,v2
, is now in Preview. Thev2
splits the monolithic client into new logically grouped api package structure. See MIGRATION.md and thev2
branch branch for more details.
This repository contains a Node.js API client for the Datadog API.
The package is under @datadog/datadog-api-client and can be installed through NPM or Yarn:
1# NPM 2npm install @datadog/datadog-api-client 3 4# Yarn 5yarn add @datadog/datadog-api-client
Here's an example getting a monitor:
1import { client, v1 } from '@datadog/datadog-api-client'; 2 3const configuration = client.createConfiguration(); 4const apiInstance = new v1.MonitorsApi(configuration); 5 6let params:v1.MonitorsApiGetMonitorRequest = { 7 // number | The ID of the monitor 8 monitorId: 1, 9}; 10 11apiInstance.getMonitor(params).then((data: v1.Monitor) => { 12 console.log('API called successfully. Returned data: ' + data); 13}).catch((error:any) => console.error(error)); 14
By default the library will use the DD_API_KEY
and DD_APP_KEY
environment variables to authenticate against the Datadog API.
To provide your own set of credentials, you need to set the appropriate keys on the configuration:
1import { client } from '@datadog/datadog-api-client'; 2 3const configurationOpts = { 4 authMethods: { 5 apiKeyAuth: "<API KEY>", 6 appKeyAuth: "<APPLICATION KEY>" 7 }, 8}; 9 10const configuration = client.createConfiguration(configurationOpts);
This client includes access to Datadog API endpoints while they are in an unstable state and may undergo breaking changes. An extra configuration step is required to enable these endpoints:
1configuration.unstableOperations["<version>.<operationName>"] = true
where <operationName>
is the name of the method used to interact with that endpoint. For example: listLogIndexes
, or getLogsIndex
.
When talking to a different server, like the eu
instance, change the server variables:
1import { client } from '@datadog/datadog-api-client'; 2 3const configuration = client.createConfiguration(); 4 5configuration.setServerVariables({ 6 site: "datadoghq.eu" 7});
If you want to disable GZIP compressed responses, set the compress
flag
on your configuration options:
1import { client } from '@datadog/datadog-api-client'; 2const configurationOpts = { 3 httpConfig: { 4 compress: false 5 }, 6}; 7 8const configuration = client.createConfiguration(configurationOpts);
If you want to enable requests logging, set the debug
flag on your configuration object:
1import { client } from '@datadog/datadog-api-client'; 2const configurationOpts = { 3 debug: true 4}; 5 6const configuration = client.createConfiguration(configurationOpts);
To enable the client to retry when rate limited (status 429) or status 500 and above:
1import { client } from '@datadog/datadog-api-client'; 2const configurationOpts = { 3 enableRetry: true 4}; 5 6const configuration = client.createConfiguration(configurationOpts);
The interval between 2 retry attempts will be the value of the x-ratelimit-reset response header when available. If not, it will be :
1(backoffMultiplier ** current_retry_count) * backoffBase
The maximum number of retry attempts is 3 by default and can be modified with
1maxRetries
To add timeout or other mechanism to cancel requests, you need an abort controller, for example the one implemented by abort-controller. You can then pass the `signal method to the HTTP configuration options:
1import { client, v1 } from '@datadog/datadog-api-client'; 2import AbortController from 'abort-controller'; 3 4const controller = new AbortController(); 5const timeout = setTimeout( 6 () => { controller.abort(); }, 7 1000, 8); 9const configurationOpts = { 10 httpConfig: { 11 signal: controller.signal 12 }, 13}; 14 15const configuration = client.createConfiguration(configurationOpts); 16 17const apiInstance = new v1.MonitorsApi(configuration); 18apiInstance.listMonitors().then((data: v1.Monitor[]) => { 19 console.log('API called successfully. Returned data: ' + data); 20}).catch((error:any) => console.error(error)).finally(() => clearTimeout(timeout));
Several listing operations have a pagination method to help consume all the items available. For example, to retrieve all your incidents:
1import { client, v2 } from "@datadog/datadog-api-client"; 2 3async function main() { 4 const configuration = client.createConfiguration(); 5 configuration.unstableOperations["v2.listIncidents"] = true; 6 const apiInstance = new v2.IncidentsApi(configuration); 7 8 for await (const incident of apiInstance.listIncidentsWithPagination()) { 9 console.log("Got incident " + incident.id); 10 } 11} 12 13main();
Zstd compression support requires users to supply their own zstd compressor callback function.
The callback should accept string arg and return compressed Buffer data.
Callback signature (body: string) => Buffer
.
For example, using zstd.ts
package:
1import { compressSync } from 'zstd.ts' 2import { client, v2 } from "@datadog/datadog-api-client"; 3 4async function main() { 5 const configurationOpts = { 6 zstdCompressorCallback: (body: string) => compressSync({input: Buffer.from(body, "utf8")}) 7 } 8 const configuration = client.createConfiguration(configurationOpts); 9 const apiInstance = new v2.MetricsApi(configuration); 10 const params: v2.MetricsApiSubmitMetricsRequest = { 11 body: { 12 series: [ 13 { 14 metric: "system.load.1", 15 type: 0, 16 points: [ 17 { 18 timestamp: Math.round(new Date().getTime() / 1000), 19 value: 0.7, 20 }, 21 ], 22 }, 23 ], 24 }, 25 contentEncoding: "zstd1", 26 }; 27 28 apiInstance.submitMetrics(params).then((data: v2.IntakePayloadAccepted) => { 29 console.log( 30 "API called successfully. Returned data: " + JSON.stringify(data) 31 ); 32 }).catch((error: any) => console.error(error)); 33} 34 35main();
You can provide custom HttpLibrary
implementation with proxy support to configuration
object. See example below:
1import pako from "pako"; 2import bufferFrom from "buffer-from"; 3import fetch from "node-fetch"; 4import { HttpsProxyAgent } from "https-proxy-agent"; 5import { v1, client } from "@datadog/datadog-api-client"; 6 7const proxyAgent = new HttpsProxyAgent('http://127.0.0.11:3128'); 8 9class HttpLibraryWithProxy implements client.HttpLibrary { 10 public debug = false; 11 12 public send(request: client.RequestContext): Promise<client.ResponseContext> { 13 const method = request.getHttpMethod().toString(); 14 let body = request.getBody(); 15 16 let compress = request.getHttpConfig().compress; 17 if (compress === undefined) { 18 compress = true; 19 } 20 21 const headers = request.getHeaders(); 22 if (typeof body === "string") { 23 if (headers["Content-Encoding"] === "gzip") { 24 body = bufferFrom(pako.gzip(body).buffer); 25 } else if (headers["Content-Encoding"] === "deflate") { 26 body = bufferFrom(pako.deflate(body).buffer); 27 } 28 } 29 30 const resultPromise = fetch(request.getUrl(), { 31 method: method, 32 body: body as any, 33 headers: headers, 34 signal: request.getHttpConfig().signal, 35 compress: compress, 36 agent: proxyAgent, 37 }).then((resp: any) => { 38 const headers: { [name: string]: string } = {}; 39 resp.headers.forEach((value: string, name: string) => { 40 headers[name] = value; 41 }); 42 43 const body = { 44 text: () => resp.text(), 45 binary: () => resp.buffer(), 46 }; 47 const response = new client.ResponseContext(resp.status, headers, body); 48 return response; 49 }); 50 51 return resultPromise; 52 } 53} 54 55const configuration = client.createConfiguration({httpApi: new HttpLibraryWithProxy()}); 56const apiInstance = new v1.DashboardsApi(configuration); 57 58apiInstance 59 .listDashboards() 60 .then((data: v1.DashboardSummary) => { 61 console.log( 62 "API called successfully. Returned data: " + JSON.stringify(data) 63 ); 64 }) 65 .catch((error: any) => console.error(error));
Documentation for API endpoints can be found in GitHub pages.
As most of the code in this repository is generated, we will only accept PRs for files that are not modified by our code-generation machinery (changes to the generated files would get overwritten). We happily accept contributions to files that are not autogenerated, such as tests and development tooling.
No vulnerabilities found.
No security vulnerabilities found.