@datadog/datadog-api-client

OpenAPI client for Datadog APIs

Usage no npm install needed!

<script type="module">
  import datadogDatadogApiClient from 'https://cdn.skypack.dev/@datadog/datadog-api-client';
</script>

README

Node.js Datadog API Client

License

This repository contains a Node.js API client for the Datadog API. The code is generated using openapi-generator and apigentools.

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 { v1 } from '@datadog/datadog-api-client';

const configuration = v1.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));

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["<operationName>"] = true

where 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 { v1 } from '@datadog/datadog-api-client';

const configuration = v1.createConfiguration();

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

Disable compressed payloads

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

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

const configuration = v1.createConfiguration(configurationOpts);

Enable requests logging

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

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

const configuration = v1.createConfiguration(configurationOpts);

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 { 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 = v1.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));

Documentation

Documentation for API endpoints can be found in 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