{"id":12769,"library":"launchdarkly-api-typescript","title":"LaunchDarkly REST API Client","description":"This package provides a TypeScript/JavaScript client for interacting with the LaunchDarkly REST API, automatically generated from their OpenAPI specification. It is built on `axios` and supports both Node.js and browser environments, with compatibility for ES5/ES6 and CommonJS/ES6 module systems. The current stable version is `22.0.0`, with frequent releases mirroring updates to the LaunchDarkly API. This client is specifically designed for custom integrations, data export, and automating feature flag workflows, such as programmatic flag management. It is crucial to note that this client library should *not* be used for integrating feature flags directly into web or mobile applications; dedicated SDKs are available for that purpose. It serves as a programmatic interface for administrative tasks rather than a runtime feature flag evaluation tool.","status":"active","version":"22.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/launchdarkly/api-client-typescript-axios","tags":["javascript","axios","typescript","openapi-client","openapi-generator","launchdarkly-api-typescript"],"install":[{"cmd":"npm install launchdarkly-api-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add launchdarkly-api-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add launchdarkly-api-typescript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used as the underlying HTTP client for making API requests.","package":"axios","optional":false}],"imports":[{"note":"Used to configure the API client with base paths, API keys, and other settings. The CommonJS require pattern is generally discouraged in modern TypeScript/JavaScript projects.","wrong":"const Configuration = require('launchdarkly-api-typescript').Configuration;","symbol":"Configuration","correct":"import { Configuration } from 'launchdarkly-api-typescript';"},{"note":"API classes (e.g., `AIConfigsApi`, `ProjectsApi`, `FeatureFlagsApi`) are named exports. Attempting to use a default import will result in a runtime error.","wrong":"import AIConfigsApi from 'launchdarkly-api-typescript';","symbol":"AIConfigsApi","correct":"import { AIConfigsApi } from 'launchdarkly-api-typescript';"},{"note":"All top-level API client classes and types are exported directly from the main package entry point. Deep imports are not necessary and can break with future internal refactorings.","wrong":"import { FlagsApi } from 'launchdarkly-api-typescript/dist/api';","symbol":"FlagsApi","correct":"import { FlagsApi } from 'launchdarkly-api-typescript';"}],"quickstart":{"code":"import { Configuration, FlagsApi } from 'launchdarkly-api-typescript';\n\nconst LAUNCHDARKLY_API_KEY = process.env.LAUNCHDARKLY_API_KEY ?? '';\nconst PROJECT_KEY = 'my-project'; // Replace with your project key\n\nif (!LAUNCHDARKLY_API_KEY) {\n  console.error('LAUNCHDARKLY_API_KEY environment variable is not set.');\n  process.exit(1);\n}\n\nasync function listFlagsForProject() {\n  const configuration = new Configuration({\n    accessToken: LAUNCHDARKLY_API_KEY,\n    basePath: 'https://app.launchdarkly.com'\n  });\n\n  const flagsApi = new FlagsApi(configuration);\n\n  try {\n    console.log(`Fetching feature flags for project: ${PROJECT_KEY}...`);\n    const response = await flagsApi.getFeatureFlags({ projectKey: PROJECT_KEY });\n    console.log(`Found ${response.items.length} feature flags.`);\n    if (response.items.length > 0) {\n      console.log('First flag key:', response.items[0].key);\n      console.log('First flag name:', response.items[0].name);\n    }\n  } catch (error) {\n    console.error('Error fetching feature flags:', error.response?.data || error.message);\n  }\n}\n\nlistFlagsForProject();","lang":"typescript","description":"This quickstart demonstrates how to initialize the LaunchDarkly API client using an access token and retrieve a list of feature flags for a specified project. It highlights the use of `Configuration` and an API-specific class like `FlagsApi`."},"warnings":[{"fix":"Use the appropriate LaunchDarkly SDK (e.g., `launchdarkly-node-server-sdk`, `launchdarkly-js-client-sdk`) for in-application feature flag evaluation.","message":"This client library is exclusively for programmatic interaction with the LaunchDarkly REST API (e.g., custom integrations, automation). It must NOT be used to integrate feature flags into client-side (web/mobile) or server-side applications for flag evaluation. For in-application feature flagging, use the official LaunchDarkly SDKs.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always review the release notes for new major versions (e.g., v20.0.0, v21.0.0, v22.0.0) before upgrading. Ensure your access token's API version setting is compatible with the client library version in use.","message":"The client library updates frequently to align with the latest version of the LaunchDarkly REST API. Major version bumps (`vX.0.0`) typically indicate significant API changes, which may include new endpoints, modified request/response bodies, or removal of deprecated features, potentially breaking existing integrations.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Retrieve `LAUNCHDARKLY_API_KEY` from secure environment variables or a secrets manager. Avoid committing API keys to version control.","message":"API access tokens are sensitive credentials. When using this client, ensure API keys are stored securely (e.g., environment variables, secret management services) and never hardcoded or exposed in client-side code.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Refer to the generated client's JSDoc/TypeScript types or the LaunchDarkly API documentation for the exact structure of request and response payloads. Use TypeScript to leverage type checking during development.","message":"The API client is generated using OpenAPI tools, which means the structure of request bodies and response objects strictly adheres to the OpenAPI specification. Mismatches in property names, types, or required fields will lead to validation errors or unexpected behavior.","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":"When handling API errors, check if `error.response` and `error.response.data` exist before accessing them, especially when expecting specific error messages from the server. For example: `error.response?.data || error.message`.","cause":"An API request failed, and the error object thrown by axios does not have the expected structure for direct access to `error.response.data`, or `error.response` is `undefined`.","error":"TypeError: Cannot read properties of undefined (reading 'data')"},{"fix":"Verify that your `LAUNCHDARKLY_API_KEY` is correctly set and is a valid access token. Check the token's permissions in the LaunchDarkly UI to ensure it has the necessary scopes for the API endpoints you are calling.","cause":"The provided API access token is missing, invalid, or does not have sufficient permissions for the requested operation.","error":"Error: Request failed with status code 401"},{"fix":"Ensure your `tsconfig.json` `module` option is set correctly for your target environment (e.g., `\"commonjs\"` for Node.js projects, `\"esnext\"` or `\"es2020\"` for browser environments with bundlers). If using CommonJS, use `const { ... } = require('pkg');` syntax.","cause":"Attempting to use ES module imports (`import ... from 'pkg'`) in a CommonJS environment without proper transpilation (e.g., via Babel or TypeScript targeting `commonjs` but configured incorrectly).","error":"TypeError: __importDefault is not a function"}],"ecosystem":"npm"}