Feature flags

Create a feature flag

POST
/api/v2/flags/{projectKey}

Create a feature flag with the given name, key, and variations.

Creating a migration flag

When you create a migration flag, the variations are pre-determined based on the number of stages in the migration.

To create a migration flag, omit the variations and defaults information. Instead, provide a purpose of migration, and migrationSettings. If you create a migration flag with six stages, contextKind is required. Otherwise, it should be omitted.

Here's an example:

{  "key": "flag-key-123",  "purpose": "migration",  "migrationSettings": {    "stageCount": 6,    "contextKind": "account"  }}

To learn more, read Migration Flags.

Authorization

ApiKey read, write
Authorization<token>

In: header

Scope: read, write

Path Parameters

projectKey*string

The project key

Formatstring

Query Parameters

clone?string

The key of the feature flag to be cloned. The key identifies the flag in your code. For example, setting clone=flagKey copies the full targeting configuration for all environments, including on/off state, from the original flag to the new flag.

Formatstring

Request Body

application/json

name*string

A human-friendly name for the feature flag

key*string

A unique key used to reference the flag in your code

description?string

Description of the feature flag. Defaults to an empty string.

includeInSnippet?boolean
Deprecated

Deprecated, use clientSideAvailability. Whether this flag should be made available to the client-side JavaScript SDK. Defaults to false.

clientSideAvailability?

Which type of client-side SDKs the feature flag is available to

variations?array<>

An array of possible variations for the flag. The variation values must be unique. If omitted, two boolean variations of true and false will be used.

temporary?boolean

Whether the flag is a temporary flag. Defaults to true.

tags?array<string>

Tags for the feature flag. Defaults to an empty array.

customProperties?

Metadata attached to the feature flag, in the form of the property key associated with a name and array of values for the metadata to associate with this flag. Typically used to store data related to an integration.

defaults?

The indices, from the array of variations, for the variations to serve by default when targeting is on and when targeting is off. These variations will be used for this flag in new environments. If omitted, the first and last variation will be used.

purpose?string

Purpose of the flag

Value in

  • "migration"
  • "holdout"
migrationSettings?

Settings relevant to flags where purpose is migration

maintainerId?string

The ID of the member who maintains this feature flag

maintainerTeamKey?string

The key of the team that maintains this feature flag

initialPrerequisites?array<>

Initial set of prerequisite flags for all environments

isFlagOn?boolean

Whether to automatically turn the flag on across all environments at creation. Defaults to false.

Response Body

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/api/v2/flags/string" \  -H "Content-Type: application/json" \  -d '{    "clientSideAvailability": {      "usingEnvironmentId": true,      "usingMobileKey": true    },    "key": "flag-key-123abc",    "name": "My Flag"  }'
{  "name": "My Flag",  "kind": "boolean",  "description": "This flag controls the example widgets",  "key": "flag-key-123abc",  "_version": 1,  "creationDate": "1494437420312",  "includeInSnippet": true,  "clientSideAvailability": "{\"usingMobileKey\":true,\"usingEnvironmentId\":false}",  "variations": [    {      "_id": "e432f62b-55f6-49dd-a02f-eb24acf39d05",      "value": true    },    {      "_id": "a00bf58d-d252-476c-b915-15a74becacb4",      "value": false    }  ],  "temporary": true,  "tags": [    "example-tag"  ],  "_links": {    "parent": {      "href": "/api/v2/flags/my-project",      "type": "application/json"    },    "self": {      "href": "/api/v2/flags/my-project/my-flag",      "type": "application/json"    }  },  "maintainerId": "569f183514f4432160000007",  "_maintainer": {    "_links": {      "self": {        "href": "/api/v2/members/569f183514f4432160000007",        "type": "application/json"      }    },    "_id": "569f183514f4432160000007",    "firstName": "Ariel",    "lastName": "Flores",    "role": "admin",    "email": "ariel@acme.com"  },  "maintainerTeamKey": "team-1",  "_maintainerTeam": {    "key": "team-key-123abc",    "name": "Example team",    "_links": {      "parent": {        "href": "/api/v2/teams",        "type": "application/json"      },      "roles": {        "href": "/api/v2/teams/example-team/roles",        "type": "application/json"      },      "self": {        "href": "/api/v2/teams/example-team",        "type": "application/json"      }    }  },  "goalIds": [],  "experiments": "{\"baselineIdx\": 0,\"items\": []}",  "customProperties": "{\"jira.issues\":{\"name\":\"Jira issues\",\"value\":[\"is-123\",\"is-456\"]}}",  "archived": false,  "archivedDate": "1494437420312",  "deprecated": false,  "deprecatedDate": "1494437420312",  "defaults": "{\"onVariation\":0,\"offVariation\":1}",  "_purpose": "string",  "migrationSettings": {    "contextKind": "device",    "stageCount": 6  },  "stale": {    "readyForCodeRemoval": true,    "readyToArchive": true,    "cleanupId": "string"  },  "environments": {    "my-environment": {      "_environmentName": "My Environment",      "_site": {        "href": "/default/my-environment/features/client-side-flag",        "type": "text/html"      },      "_summary": {        "prerequisites": 0,        "variations": {          "0": {            "contextTargets": 1,            "isFallthrough": true,            "nullRules": 0,            "rules": 0,            "targets": 1          },          "1": {            "isOff": true,            "nullRules": 0,            "rules": 0,            "targets": 0          }        }      },      "archived": false,      "contextTargets": [        {          "contextKind": "device",          "values": [            "device-key-123abc"          ],          "variation": 0        }      ],      "fallthrough": {        "variation": 0      },      "lastModified": 1627071171347,      "offVariation": 1,      "on": false,      "prerequisites": [],      "rules": [],      "salt": "61eddeadbeef4da1facecafe3a60a397",      "sel": "810edeadbeef4844facecafe438f2999492",      "targets": [        {          "contextKind": "user",          "values": [            "user-key-123abc"          ],          "variation": 0        }      ],      "trackEvents": false,      "trackEventsFallthrough": false,      "version": 1    }  }}

List feature flags GET

Get a list of all feature flags in the given project. You can include information specific to different environments by adding `env` query parameter. For example, setting `env=production` adds configuration details about your production environment to the response. You can also filter feature flags by tag with the `tag` query parameter. > #### Recommended use > > This endpoint can return a large amount of information. We recommend using some or all of these query parameters to decrease response time and overall payload size: `limit`, `env`, `query`, and `filter=creationDate`. ### Filtering flags You can filter on certain fields using the `filter` query parameter. For example, setting `filter=query:dark-mode,tags:beta+test` matches flags with the string `dark-mode` in their key or name, ignoring case, which also have the tags `beta` and `test`. The `filter` query parameter supports the following arguments: | Filter argument | Description | Example | |-----------------------|-------------|----------------------| | `applicationEvaluated` | A string. It filters the list to flags that are evaluated in the application with the given key. | `filter=applicationEvaluated:com.launchdarkly.cafe` | | `archived` | (deprecated) A boolean value. It filters the list to archived flags. | Use `filter=state:archived` instead | | `contextKindsEvaluated` | A `+`-separated list of context kind keys. It filters the list to flags which have been evaluated in the past 30 days for all of the context kinds in the list. | `filter=contextKindsEvaluated:user+application` | | `codeReferences.max` | An integer value. Use `0` to return flags that do not have code references. | `filter=codeReferences.max:0` | | `codeReferences.min` | An integer value. Use `1` to return flags that do have code references. | `filter=codeReferences.min:1` | | `creationDate` | An object with an optional `before` field whose value is Unix time in milliseconds. It filters the list to flags created before the date. | `filter=creationDate:{"before":1690527600000}` | | `evaluated` | An object that contains a key of `after` and a value in Unix time in milliseconds. It filters the list to all flags that have been evaluated since the time you specify, in the environment provided. This filter requires the `filterEnv` filter. | `filter=evaluated:{"after":1690527600000},filterEnv:production` | | `filterEnv` | A valid environment key. You must use this field for filters that are environment-specific. If there are multiple environment-specific filters, you only need to include this field once. | `filter=evaluated:{"after": 1590768455282},filterEnv:production` | | `guardedRollout` | A string, one of `any`, `monitoring`, `regressed`, `rolledBack`, `completed`, `archived`. It filters the list to flags that are part of guarded rollouts. | `filter=guardedRollout:monitoring` | | `hasExperiment` | A boolean value. It filters the list to flags that are used in an experiment. | `filter=hasExperiment:true` | | `maintainerId` | A valid member ID. It filters the list to flags that are maintained by this member. | `filter=maintainerId:12ab3c45de678910abc12345` | | `maintainerTeamKey` | A string. It filters the list to flags that are maintained by the team with this key. | `filter=maintainerTeamKey:example-team-key` | | `query` | A string. It filters the list to flags that include the specified string in their key or name. It is not case sensitive. | `filter=query:example` | | `releasePipeline` | A release pipeline key. It filters the list to flags that are either currently active in the release pipeline or have completed the release pipeline. | `filter=releasePipeline:default-release-pipeline` | | `state` | A string, either `live`, `deprecated`, or `archived`. It filters the list to flags in this state. | `filter=state:archived` | | `sdkAvailability` | A string, one of `client`, `mobile`, `anyClient`, `server`. Using `client` filters the list to flags whose client-side SDK availability is set to use the client-side ID. Using `mobile` filters to flags set to use the mobile key. Using `anyClient` filters to flags set to use either the client-side ID or the mobile key. Using `server` filters to flags set to use neither, that is, to flags only available in server-side SDKs. | `filter=sdkAvailability:client` | | `tags` | A `+`-separated list of tags. It filters the list to flags that have all of the tags in the list. | `filter=tags:beta+test` | | `type` | A string, either `temporary` or `permanent`. It filters the list to flags with the specified type. | `filter=type:permanent` | The documented values for the `filter` query are prior to URL encoding. For example, the `+` in `filter=tags:beta+test` must be encoded to `%2B`. By default, this endpoint returns all flags. You can page through the list with the `limit` parameter and by following the `first`, `prev`, `next`, and `last` links in the returned `_links` field. These links will not be present if the pages they refer to don't exist. For example, the `first` and `prev` links will be missing from the response on the first page. ### Sorting flags You can sort flags based on the following fields: - `creationDate` sorts by the creation date of the flag. - `key` sorts by the key of the flag. - `maintainerId` sorts by the flag maintainer. - `name` sorts by flag name. - `tags` sorts by tags. - `targetingModifiedDate` sorts by the date that the flag's targeting rules were last modified in a given environment. It must be used with `env` parameter and it can not be combined with any other sort. If multiple `env` values are provided, it will perform sort using the first one. For example, `sort=-targetingModifiedDate&env=production&env=staging` returns results sorted by `targetingModifiedDate` for the `production` environment. - `type` sorts by flag type All fields are sorted in ascending order by default. To sort in descending order, prefix the field with a dash ( - ). For example, `sort=-name` sorts the response by flag name in descending order. ### Expanding response LaunchDarkly supports the `expand` query param to include additional fields in the response, with the following fields: - `codeReferences` includes code references for the feature flag - `evaluation` includes evaluation information within returned environments, including which context kinds the flag has been evaluated for in the past 30 days - `migrationSettings` includes migration settings information within the flag and within returned environments. These settings are only included for migration flags, that is, where `purpose` is `migration`. For example, `expand=evaluation` includes the `evaluation` field in the response. ### Migration flags For migration flags, the cohort information is included in the `rules` property of a flag's response, and default cohort information is included in the `fallthrough` property of a flag's response. To learn more, read [Migration Flags](https://launchdarkly.com/docs/home/flags/migration).

Get feature flag GET

Get a single feature flag by key. By default, this returns the configurations for all environments. You can filter environments with the `env` query parameter. For example, setting `env=production` restricts the returned configurations to just the `production` environment. > #### Recommended use > > This endpoint can return a large amount of information. Specifying one or multiple environments with the `env` parameter can decrease response time and overall payload size. We recommend using this parameter to return only the environments relevant to your query. ### Expanding response LaunchDarkly supports the `expand` query param to include additional fields in the response, with the following fields: - `evaluation` includes evaluation information within returned environments, including which context kinds the flag has been evaluated for in the past 30 days - `migrationSettings` includes migration settings information within the flag and within returned environments. These settings are only included for migration flags, that is, where `purpose` is `migration`. For example, `expand=evaluation` includes the `evaluation` field in the response.