LaunchDarkly REST API Client

22.0.0 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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`.

import { Configuration, FlagsApi } from 'launchdarkly-api-typescript';

const LAUNCHDARKLY_API_KEY = process.env.LAUNCHDARKLY_API_KEY ?? '';
const PROJECT_KEY = 'my-project'; // Replace with your project key

if (!LAUNCHDARKLY_API_KEY) {
  console.error('LAUNCHDARKLY_API_KEY environment variable is not set.');
  process.exit(1);
}

async function listFlagsForProject() {
  const configuration = new Configuration({
    accessToken: LAUNCHDARKLY_API_KEY,
    basePath: 'https://app.launchdarkly.com'
  });

  const flagsApi = new FlagsApi(configuration);

  try {
    console.log(`Fetching feature flags for project: ${PROJECT_KEY}...`);
    const response = await flagsApi.getFeatureFlags({ projectKey: PROJECT_KEY });
    console.log(`Found ${response.items.length} feature flags.`);
    if (response.items.length > 0) {
      console.log('First flag key:', response.items[0].key);
      console.log('First flag name:', response.items[0].name);
    }
  } catch (error) {
    console.error('Error fetching feature flags:', error.response?.data || error.message);
  }
}

listFlagsForProject();

view raw JSON →