This guide goes over how to migrate your code from using the monolithic @datadog/datadog-api-client package to the new logically grouped packages structure.
- The
@datadog/datadog-api-clientpackage now only contains core components and configuration objects. - Service-specific code (e.g.,
Monitor) has been moved to individual packages inservices/directory- Each API grouping is in its own dedicated package following the naming convention
@datadog/datadog-api-client-{apiName}
- Each API grouping is in its own dedicated package following the naming convention
-
serverVariables,operationServerVariablesandunstableOperationkeys in the configuration object now follow the same format:{ apiName }.{ apiVersion }.{operation}
Install the required packages:
# Service-specific packages (install only the ones you need)
npm install @datadog/datadog-api-client-monitors
# OR
yarn add @datadog/datadog-api-client-monitors
# ... and so on for other servicesAll of the clients directly depend on the @datadog/datadog-api-client package for core components such as Configuration object.
You can manually install the client using:
npm install @datadog/datadog-api-client@^2.0.0-beta.1
# OR
yarn add @datadog/datadog-api-client@^2.0.0-beta.1Replace imports of core components from the main package:
// Old
import { client } from "@datadog/datadog-api-client";
const configuration = client.createConfiguration()// New
import { createConfiguration } from "@datadog/datadog-api-client";
const configuration = createConfiguration()Update imports for service-specific models and APIs:
// Old
import { v1 } from "@datadog/datadog-api-client";
const apiInstance = new v1.MonitorsApi();// New
import { v1 } from "@datadog/datadog-api-client-monitors";
const apiInstance = new v1.MonitorsApi();Update your configuration object to use the new format { apiName }.{ apiVersion }.{ operation }
// Old
const configuration = createConfiguration({
operationServerIndices: {
"v2.LogsApi.submitLog": 0
},
unstableOperations: {
"v2.createOpenAPI": true
}
});// New
const configuration = createConfiguration({
operationServerIndices: {
"LogsApi.v2.submitLog": 0
},
operationServerVariables: {
"LogsApi.v2.submitLog": {
"site": "datadoghq.eu"
}
},
unstableOperations: {
"APIManagementApi.v2.createOpenAPI": true
}
});Here's a complete example showing how to migrate a typical use case:
// Old
import { v1, client } from "@datadog/datadog-api-client";
const configuration = client.createConfiguration({
authMethods: {
apiKeyAuth: "YOUR_API_KEY",
appKeyAuth: "YOUR_APP_KEY"
}
});
const api = new v1.MonitorsApi(configuration);// New
import { Configuration, createConfiguration } from "@datadog/datadog-api-client";
import { v1 } from "@datadog/datadog-api-client-monitors";
const configuration = createConfiguration({
authMethods: {
apiKeyAuth: "YOUR_API_KEY",
appKeyAuth: "YOUR_APP_KEY"
}
});
const api = new v1.MonitorsApi(configuration);See Clients section in the following README.md
If you encounter any issues during migration, please:
- Check the API documentation
- Open an issue in the GitHub repository
- Contact Datadog Support