Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@datadog/datadog-api-client

DataDog2.6mApache-2.01.31.0TypeScript support: included

OpenAPI client for Datadog APIs

api, fetch, datadog, typescript, openapi-client, openapi-generator

readme

Node.js Datadog API Client

License

This repository contains a Node.js API client for the Datadog API.

How to install

The package is under @datadog/datadog-api-client and can be installed through NPM or Yarn:

# NPM
npm install @datadog/datadog-api-client

# Yarn
yarn add @datadog/datadog-api-client

Getting Started

Here's an example getting a monitor:

import { client, v1 } from '@datadog/datadog-api-client';

const configuration = client.createConfiguration();
const apiInstance = new v1.MonitorsApi(configuration);

let params:v1.MonitorsApiGetMonitorRequest = {
  // number | The ID of the monitor
  monitorId: 1,
};

apiInstance.getMonitor(params).then((data: v1.Monitor) => {
  console.log('API called successfully. Returned data: ' + data);
}).catch((error:any) => console.error(error));

Authentication

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:

import { client } from '@datadog/datadog-api-client';

const configurationOpts = {
  authMethods: {
    apiKeyAuth: "<API KEY>",
    appKeyAuth: "<APPLICATION KEY>"
  },
};

const configuration = client.createConfiguration(configurationOpts);

Unstable Endpoints

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:

configuration.unstableOperations["<version>.<operationName>"] = true

where <operationName> is the name of the method used to interact with that endpoint. For example: listLogIndexes, or getLogsIndex.

Changing Server

When talking to a different server, like the eu instance, change the server variables:

import { client } from '@datadog/datadog-api-client';

const configuration = client.createConfiguration();

configuration.setServerVariables({
  site: "datadoghq.eu"
});

Disable compressed payloads

If you want to disable GZIP compressed responses, set the compress flag on your configuration options:

import { client } from '@datadog/datadog-api-client';
const configurationOpts = {
  httpConfig: {
    compress: false
  },
};

const configuration = client.createConfiguration(configurationOpts);

Enable requests logging

If you want to enable requests logging, set the debug flag on your configuration object:

import { client } from '@datadog/datadog-api-client';
const configurationOpts = {
  debug: true
};

const configuration = client.createConfiguration(configurationOpts);

Enable retry

To enable the client to retry when rate limited (status 429) or status 500 and above:

import { client } from '@datadog/datadog-api-client';
const configurationOpts = {
  enableRetry: true
};

const 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 :

(backoffMultiplier ** current_retry_count) * backoffBase

The maximum number of retry attempts is 3 by default and can be modified with

maxRetries

Adding timeout to requests

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:

import { client, v1 } from '@datadog/datadog-api-client';
import AbortController from 'abort-controller';

const controller = new AbortController();
const timeout = setTimeout(
  () => { controller.abort(); },
  1000,
);
const configurationOpts = {
  httpConfig: {
    signal: controller.signal
  },
};

const configuration = client.createConfiguration(configurationOpts);

const apiInstance = new v1.MonitorsApi(configuration);
apiInstance.listMonitors().then((data: v1.Monitor[]) => {
  console.log('API called successfully. Returned data: ' + data);
}).catch((error:any) => console.error(error)).finally(() => clearTimeout(timeout));

Pagination

Several listing operations have a pagination method to help consume all the items available. For example, to retrieve all your incidents:

import { client, v2 } from "@datadog/datadog-api-client";

async function main() {
  const configuration = client.createConfiguration();
  configuration.unstableOperations["v2.listIncidents"] = true;
  const apiInstance = new v2.IncidentsApi(configuration);

  for await (const incident of apiInstance.listIncidentsWithPagination()) {
      console.log("Got incident " + incident.id);
  }
}

main();

Zstd compression

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:

import { compressSync } from 'zstd.ts'
import { client, v2 } from "@datadog/datadog-api-client";

async function main() {
  const configurationOpts = {
    zstdCompressorCallback: (body: string) => compressSync({input: Buffer.from(body, "utf8")})
  }
  const configuration = client.createConfiguration(configurationOpts);
  const apiInstance = new v2.MetricsApi(configuration);
  const params: v2.MetricsApiSubmitMetricsRequest = {
      body: {
          series: [
              {
                  metric: "system.load.1",
                  type: 0,
                  points: [
                      {
                          timestamp: Math.round(new Date().getTime() / 1000),
                          value: 0.7,
                      },
                  ],
              },
          ],
      },
      contentEncoding: "zstd1",
  };

  apiInstance.submitMetrics(params).then((data: v2.IntakePayloadAccepted) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  }).catch((error: any) => console.error(error));
}

main();

Configure proxy

You can provide custom HttpLibrary implementation with proxy support to configuration object. See example below:

import pako from "pako";
import bufferFrom from "buffer-from";
import fetch from "node-fetch";
import { HttpsProxyAgent } from "https-proxy-agent";
import { v1, client } from "@datadog/datadog-api-client";

const proxyAgent = new HttpsProxyAgent('http://127.0.0.11:3128');

class HttpLibraryWithProxy implements client.HttpLibrary {
    public debug = false;

    public send(request: client.RequestContext): Promise<client.ResponseContext> {
        const method = request.getHttpMethod().toString();
        let body = request.getBody();

        let compress = request.getHttpConfig().compress;
        if (compress === undefined) {
            compress = true;
        }

        const headers = request.getHeaders();
        if (typeof body === "string") {
            if (headers["Content-Encoding"] === "gzip") {
                body = bufferFrom(pako.gzip(body).buffer);
            } else if (headers["Content-Encoding"] === "deflate") {
                body = bufferFrom(pako.deflate(body).buffer);
            }
        }

        const resultPromise = fetch(request.getUrl(), {
            method: method,
            body: body as any,
            headers: headers,
            signal: request.getHttpConfig().signal,
            compress: compress,
            agent: proxyAgent,
        }).then((resp: any) => {
            const headers: { [name: string]: string } = {};
            resp.headers.forEach((value: string, name: string) => {
                headers[name] = value;
            });

            const body = {
                text: () => resp.text(),
                binary: () => resp.buffer(),
            };
            const response = new client.ResponseContext(resp.status, headers, body);
            return response;
        });

        return resultPromise;
    }
}

const configuration = client.createConfiguration({httpApi: new HttpLibraryWithProxy()});
const apiInstance = new v1.DashboardsApi(configuration);

apiInstance
    .listDashboards()
    .then((data: v1.DashboardSummary) => {
        console.log(
            "API called successfully. Returned data: " + JSON.stringify(data)
        );
    })
    .catch((error: any) => console.error(error));

Documentation

Documentation for API endpoints can be found in GitHub pages.

Contributing

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.

Author

support@datadoghq.com

License

Apache License, v2.0

changelog

CHANGELOG

1.31.0 / 2024-12-17

Added

New Contributors

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.30.0...v1.31.0

1.30.0 / 2024-11-07

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.29.0...v1.30.0

1.29.0 / 2024-10-02

Fixed

New Contributors

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.28.0...v1.29.0

1.28.0 / 2024-09-04

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.27.0...v1.28.0

1.27.0 / 2024-08-12

Fixed

New Contributors

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.26.0...v1.27.0

1.26.0 / 2024-07-01

Fixed

New Contributors

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.25.0...v1.26.0

1.25.0 / 2024-05-21

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.24.0...v1.25.0

1.24.0 / 2024-04-11

Fixed

New Contributors

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.23.0...v1.24.0

1.23.0 / 2024-03-13

Fixed

New Contributors

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.22.0...v1.23.0

1.22.0 / 2024-02-06

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.21.0...v1.22.0

1.21.0 / 2024-01-10

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.20.0...v1.21.0

1.20.0 / 2023-12-12

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.19.0...v1.20.0

1.19.0 / 2023-11-15

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.18.0...v1.19.0

1.18.0 / 2023-10-16

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.17.0...v1.18.0

1.17.0 / 2023-09-14

Fixed

New Contributors

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.16.0...v1.17.0

1.16.0 / 2023-08-23

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.15.0...v1.16.0

1.15.0 / 2023-07-20

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.14.0...v1.15.0

1.14.0 / 2023-06-27

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.13.0...v1.14.0

1.13.0 / 2023-05-31

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.12.0...v1.13.0

1.12.0 / 2023-04-18

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.11.0...v1.12.0

1.11.0 / 2023-03-14

Added

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.10.0...v1.11.0

1.10.0 / 2023-02-15

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.9.0...v1.10.0

1.9.0 / 2023-02-08

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.8.0...v1.9.0

1.8.0 / 2023-01-11

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.7.0...v1.8.0

1.7.0 / 2022-12-20

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.6.0...v1.7.0

1.6.0 / 2022-11-16

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.5.0...v1.6.0

1.5.0 / 2022-10-24

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.4.0...v1.5.0

1.4.0 / 2022-10-03

Fixed

New Contributors

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.3.0...v1.4.0

1.3.0 / 2022-08-31

Fixed

New Contributors

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.2.0...v1.3.0

1.2.0 / 2022-08-01

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.1.0...v1.2.0

1.1.0 / 2022-07-19

Fixed

New Contributors

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.0.0...v1.1.0

1.0.0 / 2022-06-10

Fixed

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.0.0-beta.9...v1.0.0

1.0.0-beta.9 / 2022-03-03

Fixed

New Contributors

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.0.0-beta.8...v1.0.0-beta.9

1.0.0-beta.8 / 2022-02-18

Fixed

New Contributors

Full Changelog: https://github.com/DataDog/datadog-api-client-typescript/compare/v1.0.0-beta.7...v1.0.0-beta.8

1.0.0-beta.7 / 2022-01-21

  • [Added] Add filter[deleted] parameter for searching recently deleted dashboards. See #479.
  • [Added] Expose new signal configuration for timeout. See #484.
  • [Added] Add support for authentication and proxy options in Synthetics. See #443.
  • [Added] Support formulas and functions in Treemap Widget. See #473.
  • [Added] Add Cloud Workload Security Agent Rules API. See #460.
  • [Added] Add offset and limit parameters to usage listing endpoint. See #466.
  • [Added] Add monthly usage attribution API spec. See #452.
  • [Added] Add missing hosts metadata fields. See #447.
  • [Added] Add replay_session_count and update documentation for rum_session_count. See #465.
  • [Added] Add retry options for a step in Synthetics multistep test. See #455.
  • [Added] Document author_name in dashboard response. See #453.
  • [Added] Add organization metadata for RUM sessions usage and expose rum_browser_and_mobile_session_count. See #448.
  • [Added] Add endpoint to retrieve hourly usage attribution. See #426.
  • [Added] Add support for scoped application keys. See #408.
  • [Added] Add endpoint for cloning roles. See #434.
  • [Added] Add organization metadata for audit logs, CWS, CSPM, DBM. See #440.
  • [Added] Add ci-pipelines alert to monitors enum. See #433.
  • [Added] Add support for sunburst widget in dashboard. See #438.
  • [Added] Add Limit Note for Hourly Requests. See #403.
  • [Added] Add support for unstable operations. See #402.
  • [Added] Expose estimated logs usage in Usage Attribution API. See #404.
  • [Added] Add endpoint to get corrections applied to an SLO. See #386.
  • [Added] Expose public_id and org_name in Usage API response. See #390.
  • [Added] Document query in MonitorSearchResult. See #387.
  • [Added] Add 429 error responses. See #371.
  • [Added] Add support for profiled Fargate tasks in Usage API. See #368.
  • [Added] Add support for websocket synthetics tests. See #369.
  • [Added] Add support for Synthetics UDP API tests. See #363.
  • [Added] Add trigger synthetics tests endpoint. See #337.
  • [Added] Add RUM Units to usage metering API. See #357.
  • [Added] Add formulas and functions support to change widget. See #263.
  • [Added] Add support for Azure automute option. See #343.
  • [Added] Add v2 intake endpoint. See #336.
  • [Fixed] Clarify required fields for SyntheticsAPIStep, SyntheticsAPITest, and SyntheticsBrowserTest. See #367.
  • [Fixed] Fixes to Cloud Workload Security API. See #477.
  • [Fixed] Make downtime weekdays nullable. See #457.
  • [Fixed] Fix a typo in an incident field attribute description. See #415.
  • [Fixed] Fix SecurityMonitoringSignal.attributes.tags type. See #417.
  • [Fixed] Allow null in required field. See #421.
  • [Fixed] Be more resilient to plain text errors. See #399.
  • [Fixed] Fix monitor timeout_h example and limits. See #382.
  • [Fixed] Remove event title length constraint. See #379.
  • [Fixed] Mark batch_id in Synthetics Trigger CI response as nullable. See #373.
  • [Fixed] SLO Correction attributes rrule and duration can be nullable. See #365.
  • [Fixed] Change UsageNetworkFlowsHour.indexed_event_count to match actual API. See #362.
  • [Fixed] Fix type for ratio_in_month in usage metering. See #352.
  • [Changed] Use pako for compressing payloads. See #487.
  • [Changed] Remove read only fields in EventCreateRequest. See #475.
  • [Changed] Change pagination arguments for querying usage attribution. See #451.
  • [Changed] Fix required target in Synthetics assertions and type in step results. See #366.
  • [Deprecated] Remove session counts from RUM units response. See #429.
  • [Removed] Remove deprecated AgentRule field in Security Rules API for CWS. See #446.

1.0.0-beta.6 / 2021-11-03

  • [Added] Added available_values property to template variables schema. See #258.
  • [Added] Add follow_redirects options to test request in Synthetics. See #267.
  • [Added] ApmDependencyStatsQuery for formulas and functions dashboard widgets. See #278.
  • [Added] Add formula and function APM resource stats query definition for dashboards. See #279.
  • [Added] Add support for funnel widget in dashboards. See #286.
  • [Added] Add information about creator to Synthetics tests details. See #295.
  • [Added] Add support for gzip and deflate encoding. See #291.
  • [Added] Add support for formulas and functions in the Scatterplot Widget for dashboards. See #284.
  • [Added] Document encoding in metrics intake. See #306.
  • [Added] Add servername property to SSL Synthetics tests request. See #305.
  • [Added] Add renotify_occurrences and renotify_statuses monitor options. See #315.
  • [Added] Add type and is_template properties to notebooks. See #317.
  • [Added] Add endpoint to get details of a Synthetics batch. See #262.
  • [Added] Add SDS to usage metering endpoint. See #321.
  • [Added] Add metrics_collection_enabled, cspm_resource_collection_enabled and resource_collection_enabled to AWS integration request. See #319.
  • [Added] Add apm_stats_query property to DistributionWidgetRequest. See #328.
  • [Added] Add aggregations attribute to v2 metric tag configuration. See #273.
  • [Added] Add support for RRULE fields in SLO corrections. See #302.
  • [Added] Improve typescript server management. See #322.
  • [Fixed] Fix SLO history error response type for overall errors. See #265.
  • [Fixed] Bump url-parse from 1.5.1 to 1.5.2. See #270.
  • [Fixed] Mark SLO Correction Type as required. See #264.
  • [Fixed] Make the name property required for APM Dependency Stat Query Dashboard Widget. See #283.
  • [Fixed] Show body content for unknown responses. See #287.
  • [Fixed] Fix typo in usage attribution field names for profiled containers. See #296.
  • [Fixed] Make sure that OpenAPI definition are valid with real server responses. See #294.
  • [Fixed] Fix incidents schemas. See #303.
  • [Fixed] IncidentFieldAttributesMultipleValue can be nullable. See #304.
  • [Fixed] Remove event title length constraint. See #300.
  • [Fixed] Use plural form for dbm hosts usage properties. See #312.
  • [Security] Bump tmpl from 1.0.4 to 1.0.5. See #289.
  • [Changed] Fix SLO history schema for groups and monitors fields. See #272.
  • [Changed] Remove metadata from required list for metric SLO history endpoint. See #277.
  • [Changed] Use AVG aggregation function for DBM queries. See #290.
  • [Changed] Enable compression in responses. See #314.
  • [Changed] Update Synthetics CI test metadata. See #311.
  • [Deprecated] Update property descriptions for Dashboard RBAC release. See #335.

1.0.0-beta.5 / 2021-08-27

  • [Added] Add config variables to Synthetics browser test config. See #257.
  • [Added] Add DBM usage endpoint. See #244.
  • [Added] Add audit alert monitor type. See #254.
  • [Added] Add batch_id to the synthetics trigger endpoint response. See #252.
  • [Added] Adding support for security monitoring rule type property. See #242.
  • [Added] Add events data source to Dashboard widgets. See #243.
  • [Added] Add restricted roles for Synthetics global variables. See #248.
  • [Added] Add webhooks integration. See #247.
  • [Added] Add missing synthetics variable parser type x_path. See #246.
  • [Added] Improve resiliency of typescript SDK when deserialising enums/oneOfs. See #217.
  • [Added] Add audit_stream to ListStreamSource. See #236.
  • [Added] Add percentile to dashboard WidgetAggregator schema. See #232.
  • [Added] Add id_str property to Event response. See #238.
  • [Added] Add edge to Synthetics devices. See #241.
  • [Added] Add endpoints to manage Service Accounts v2. See #224.
  • [Added] Add new_group_delay and deprecate new_host_delay monitor properties. See #235.
  • [Added] Add include_descendants param to usage attribution API. See #240.
  • [Added] Add support for list widget in dashboards. See #206.
  • [Added] Extend dashbords table widget requests to support formulas and functions. See #223.
  • [Added] Add CSPM to usage attribution. See #214.
  • [Added] Add support for dashboard bulk delete, restore endpoints. See #204.
  • [Added] Add support for audit logs data source in dashboards. See #218.
  • [Fixed] Fix DD_SITE management. See #259.
  • [Fixed] Minor fixes of the incident schema. See #249.

1.0.0-beta.4 / 2021-07-14

  • [Added] Add allow_insecure option for multistep steps in Synthetics. See #212.
  • [Added] Add support for GET /api/v2/application_keys/{app_key_id}. See #205.
  • [Added] Add meta property with pagination info to SLOCorrectionList endpoint response. See #202.
  • [Added] Add support for treemap widget. See #195.
  • [Added] Add missing properties query_index and tag_set to MetricsQueryMetadata. See #186.
  • [Added] Add missing fields hasExtendedTitle, type, version and updateAuthorId for Security Monitoring Rule endpoints. See #182.
  • [Added] Dashboard RBAC role support. See #179.
  • [Added] Add missing fields in usage billable summary keys. See #176.
  • [Fixed] Fix status property name for browser error status in Synthetics. See #213.
  • [Fixed] Remove US only constraint for AWS tag filtering. See #189.
  • [Fixed] Handle null in query metrics unit. See #184.
  • [Security] Bump color-string from 1.5.4 to 1.5.5. See #200.
  • [Changed] Add separate schema for deleting AWS account. See #211.
  • [Changed] Specify format of report_id parameter. See #209.
  • [Changed] Remove Synthetics tick interval enum. See #187.
  • [Removed] Remove deprecated endpoints /api/v1/usage/traces and /api/v1/usage/tracing-without-limits. See #215.

1.0.0-beta.3 / 2021-06-09

  • [Added] Add monitor name and priority options. See #173.
  • [Fixed] Fix type of day/month response attribute in custom metrics usage. See #170.
  • [Added] Add CWS to usage metering endpoint. See #155.
  • [Changed] usage metering - rename compliance to cspm and add audit logs. See #168.

1.0.0-beta.0 / 2021-05-31

  • [Added] Initial beta release of the Datadog API Client