{"id":13080,"library":"dogapi","title":"Datadog API Node.JS Client","description":"dogapi is a Node.js client library that provides an interface to the Datadog HTTP API, enabling programmatic interaction with Datadog services for metrics, events, dashboards, and more. It is currently at version 2.8.4. This library focuses exclusively on the HTTP API and does not include functionality for interacting with a local `dogstatsd` server; for StatsD, users are directed to alternative packages like `node-dogstatsd`. The release cadence is driven by changes to the Datadog API or internal library improvements. Key differentiators include its direct mapping to the Datadog API endpoints and clear separation from StatsD client concerns, which are often bundled in other monitoring libraries.","status":"active","version":"2.8.4","language":"javascript","source_language":"en","source_url":"git://github.com/brettlangdon/node-dogapi","tags":["javascript","datadog","api","datadog api","dog","dogapi","dog api"],"install":[{"cmd":"npm install dogapi","lang":"bash","label":"npm"},{"cmd":"yarn add dogapi","lang":"bash","label":"yarn"},{"cmd":"pnpm add dogapi","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This library is primarily CommonJS. While Node.js's ESM interop might allow `import dogapi from 'dogapi'`, the recommended and officially supported way is `require()` for this CJS-first package.","wrong":"import dogapi from 'dogapi';","symbol":"dogapi","correct":"const dogapi = require('dogapi');"},{"note":"The library requires initialization with API and application keys before making any API calls. This function sets up the global configuration.","symbol":"dogapi.initialize","correct":"const dogapi = require('dogapi');\ndogapi.initialize(options);"},{"note":"The argument format for `send` and `send_all` changed significantly in version 2.x.x; consult documentation for correct point formats (e.g., `[[timestamp, value]]` or `value`).","symbol":"dogapi.metric.send","correct":"const dogapi = require('dogapi');\ndogapi.metric.send('metric.name', [[now, 50]]);"}],"quickstart":{"code":"const dogapi = require('dogapi');\n\nconst options = {\n  api_key: process.env.DATADOG_API_KEY ?? '',\n  app_key: process.env.DATADOG_APP_KEY ?? '',\n  // For Datadog EU users, uncomment and set the correct host:\n  // api_host: 'app.datadoghq.eu'\n};\n\ndogapi.initialize(options);\n\nconst now = Math.floor(new Date().getTime() / 1000);\n\ndogapi.metric.send(\n  'my.application.response_time',\n  [[now, 123.45]], // Example for a timed metric point (v2.x.x format)\n  ['env:production', 'service:web-api'],\n  function(err, results) {\n    if (err) {\n      console.error('Error sending metric:', err);\n    } else {\n      console.log('Metric sent successfully:', results);\n    }\n  }\n);\n\ndogapi.event.create(\n  {\n    title: 'New Feature Rollout',\n    text: 'Version 2.8.4 deployed with new user management feature.',\n    tags: ['env:production', 'team:devops', 'release:v2.8.4'],\n    alert_type: 'info'\n  },\n  function(err, results) {\n    if (err) {\n      console.error('Error creating event:', err);\n    } else {\n      console.log('Event created successfully:', results);\n    }\n  }\n);","lang":"javascript","description":"This quickstart demonstrates how to initialize the dogapi client with API keys (using environment variables for security) and subsequently send a custom timed metric and an event to Datadog's HTTP API."},"warnings":[{"fix":"Review the official `dogapi` documentation or the README section 'Major changes from 1.x.x to 2.x.x' to correctly format metric points when upgrading from 1.x.x.","message":"The argument format for `dogapi.metric.send` and `dogapi.metric.send_all` changed significantly in version 2.x.x. The `points` argument now expects `[[timestamp, value]]` or `[value, value2]` or `value` for a single point, instead of the `[timestamp, value]` or `value` in 1.x.x.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"When calling `dogapi.initialize()`, include `api_host: 'app.datadoghq.eu'` (or your regional host) in the options object.","message":"Users on the Datadog EU site (`app.datadoghq.eu`) or other non-US regions must explicitly set the `api_host` option during initialization to their respective regional endpoint (e.g., `app.datadoghq.eu`) to ensure metrics and events are sent to the correct location. The default `api_host` points to the US site.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For Datadog StatsD functionality, use a dedicated StatsD client library such as `node-dogstatsd`, which is designed for UDP communication with the local agent.","message":"This `dogapi` library is solely for interacting with the Datadog HTTP API. It does not provide functionality for `dogstatsd`, which is used for sending metrics via UDP to a local agent. Attempting to use `dogapi` for StatsD purposes will fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Store `DATADOG_API_KEY` and `DATADOG_APP_KEY` securely in environment variables and access them using `process.env.DATADOG_API_KEY` or a secrets management system.","message":"Datadog API and Application keys are sensitive credentials and should never be hardcoded directly into your application's source code. Exposing them can lead to unauthorized access and data manipulation within your Datadog account.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `api_key` and `app_key` are correctly set in the options object passed to `dogapi.initialize()`. Double-check the keys on your Datadog account settings page (https://app.datadoghq.com/account/settings#api).","cause":"The `dogapi.initialize` method was called without providing valid `api_key` and `app_key` in the options object, or the provided keys are incorrect.","error":"Error: API key or application key missing (or similar error message indicating missing credentials)"},{"fix":"If you are on Datadog EU, ensure `api_host: 'app.datadoghq.eu'` is explicitly included in the options when calling `dogapi.initialize()`.","cause":"The `api_host` configuration is incorrect or missing for users on Datadog's EU region, or other non-US regions. The client is sending data to the default US endpoint.","error":"Metric data is not appearing in Datadog, or appears on the wrong site (e.g., US instead of EU)."},{"fix":"Update metric point formats according to version 2.x.x requirements. For `dogapi.metric.send`, use `[[timestamp, value]]` for a single timed value, or `value` for an untimed value. For `dogapi.metric.send_all`, ensure each metric's `points` array contains arrays of `[timestamp, value]` or single values.","cause":"Using the pre-2.x.x metric point format (e.g., `[timestamp, value]`) for `dogapi.metric.send` or `dogapi.metric.send_all` with version 2.x.x or later.","error":"Error: Invalid metric point format (e.g., 'points' array expects array of arrays or single value)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}