For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Sign inTry it free
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
  • REST API overview
    • Access Tokens
    • Account Members
    • Account Usage Beta
    • AI Configs
    • Announcements
    • Applications Beta
    • Approvals
    • Approvals Beta
    • Audit Log
    • Code References
    • Contexts
    • Context Settings
    • Custom Roles
    • Data Export Destinations
    • Environments
    • Experiments
    • Feature Flags
      • POSTCopy feature flag
      • POSTCreate a feature flag
      • DELDelete feature flag
      • GETGet expiring context targets for feature flag
      • GETGet expiring user targets for feature flag
      • GETGet feature flag
      • GETGet feature flag status
      • GETGet flag status across environments
      • POSTGet migration safety issues
      • GETList feature flag statuses
      • GETList feature flags
      • PATCHUpdate expiring context targets on feature flag
      • PATCHUpdate expiring user targets on feature flag
      • PATCHUpdate feature flag
    • Feature Flags Beta
    • Flag Import Configurations Beta
    • Flag Links Beta
    • Flag Triggers
    • Follow Flags
    • Holdouts Beta
    • Insights Charts Beta
    • Insights Deployments Beta
    • Insights Flag Events Beta
    • Insights Pull Requests Beta
    • Insights Repositories Beta
    • Insights Scores Beta
    • Integration Audit Log Subscriptions
    • Integration Delivery Configurations Beta
    • Integrations Beta
    • Layers
    • Metrics
    • Metrics Beta
    • OAuth2 Clients
    • Persistent Store Integrations Beta
    • Projects
    • Relay Proxy Configurations
    • Release Pipelines Beta
    • Releases Beta
    • Scheduled Changes
    • Segments
    • Tags
    • Teams
    • Teams Beta
    • Users
    • Users Beta
    • User Settings
    • Views Beta
    • Webhooks
    • Workflows
    • Workflow Templates
    • Other
Sign inTry it free
LogoLogo
REST API overviewFeature Flags

Create a feature flag

POST
/api/v2/flags/:projectKey
POST
/api/v2/flags/:projectKey
$curl -X POST https://app.launchdarkly.com/api/v2/flags/projectKey \
> -H "Authorization: <apiKey>" \
> -H "Content-Type: application/json" \
> -d '{
> "name": "My Flag",
> "key": "flag-key-123abc",
> "clientSideAvailability": {
> "usingEnvironmentId": true,
> "usingMobileKey": true
> }
>}'
1{
2 "name": "My Flag",
3 "kind": "boolean",
4 "key": "flag-key-123abc",
5 "_version": 1,
6 "creationDate": 1494437420312,
7 "variations": [
8 {
9 "value": null,
10 "_id": "e432f62b-55f6-49dd-a02f-eb24acf39d05"
11 },
12 {
13 "value": null,
14 "_id": "a00bf58d-d252-476c-b915-15a74becacb4"
15 }
16 ],
17 "temporary": true,
18 "tags": [
19 "example-tag"
20 ],
21 "_links": {
22 "parent": {
23 "href": "/api/v2/flags/my-project",
24 "type": "application/json"
25 },
26 "self": {
27 "href": "/api/v2/flags/my-project/my-flag",
28 "type": "application/json"
29 }
30 },
31 "experiments": {
32 "baselineIdx": 1,
33 "items": [
34 {
35 "metricKey": "my-metric",
36 "_metric": {
37 "_id": "5902deadbeef667524a01290",
38 "_versionId": "version-id-123abc",
39 "key": "metric-key-123abc",
40 "name": "My metric",
41 "kind": "custom",
42 "_links": {
43 "parent": {
44 "href": "/api/v2/metrics/my-project",
45 "type": "application/json"
46 },
47 "self": {
48 "href": "/api/v2/metrics/my-project/my-metric",
49 "type": "application/json"
50 }
51 },
52 "tags": [],
53 "_creationDate": 1628192791148,
54 "dataSource": {
55 "key": "string",
56 "environmentKey": "string",
57 "_name": "string",
58 "_integrationKey": "string"
59 },
60 "experimentCount": 0,
61 "metricGroupCount": 0,
62 "activeExperimentCount": 2,
63 "activeGuardedRolloutCount": 1,
64 "_version": 1,
65 "_attachedFlagCount": 0,
66 "_site": {},
67 "_access": {
68 "denied": [
69 {
70 "action": "string",
71 "reason": {
72 "effect": "allow",
73 "resources": [
74 "proj/*:env/*;qa_*:/flag/*"
75 ],
76 "notResources": [
77 "string"
78 ],
79 "actions": [
80 "*"
81 ],
82 "notActions": [
83 "string"
84 ],
85 "role_name": "string"
86 }
87 }
88 ],
89 "allowed": [
90 {
91 "action": "string",
92 "reason": {
93 "effect": "allow",
94 "resources": [
95 "proj/*:env/*;qa_*:/flag/*"
96 ],
97 "notResources": [
98 "string"
99 ],
100 "actions": [
101 "*"
102 ],
103 "notActions": [
104 "string"
105 ],
106 "role_name": "string"
107 }
108 }
109 ]
110 },
111 "lastModified": {
112 "date": "2021-08-05T19:46:31.148082Z"
113 },
114 "maintainerId": "569fdeadbeef1644facecafe",
115 "_maintainer": {
116 "_links": {
117 "self": {
118 "href": "/api/v2/members/569f183514f4432160000007",
119 "type": "application/json"
120 }
121 },
122 "_id": "569f183514f4432160000007",
123 "role": "admin",
124 "email": "ariel@acme.com"
125 },
126 "description": "string",
127 "category": "Error monitoring",
128 "isNumeric": true,
129 "successCriteria": "HigherThanBaseline",
130 "unit": "string",
131 "eventKey": "Order placed",
132 "analysisUnits": [
133 "user"
134 ],
135 "filters": {
136 "type": "contextAttribute",
137 "op": "in",
138 "values": [
139 "JP"
140 ],
141 "negate": false
142 },
143 "unitAggregationType": "average",
144 "analysisType": "mean",
145 "percentileValue": 95,
146 "eventDefault": {
147 "disabled": true,
148 "value": 0
149 },
150 "lastSeen": 1,
151 "archived": true,
152 "archivedAt": 1609459200000,
153 "selector": "string",
154 "urls": [
155 "[{\"kind\":\"exact\",\"url\":\"https://www.example.com/page1\"}]"
156 ],
157 "windowStartOffset": 1,
158 "windowEndOffset": 1,
159 "traceQuery": "service.name = \"checkout\"",
160 "traceValueLocation": "duration",
161 "randomizationUnits": [
162 "user"
163 ]
164 },
165 "environments": [
166 "production",
167 "test",
168 "my-environment"
169 ],
170 "_environmentSettings": {}
171 }
172 ]
173 },
174 "customProperties": "{\"jira.issues\":{\"name\":\"Jira issues\",\"value\":[\"is-123\",\"is-456\"]}}",
175 "archived": false,
176 "description": "This flag controls the example widgets",
177 "clientSideAvailability": {},
178 "maintainerId": "569f183514f4432160000007",
179 "_maintainer": {
180 "_links": {
181 "self": {
182 "href": "/api/v2/members/569f183514f4432160000007",
183 "type": "application/json"
184 }
185 },
186 "_id": "569f183514f4432160000007",
187 "role": "admin",
188 "email": "ariel@acme.com",
189 "firstName": "Ariel",
190 "lastName": "Flores"
191 },
192 "maintainerTeamKey": "team-1",
193 "_maintainerTeam": {
194 "key": "team-key-123abc",
195 "name": "Example team",
196 "_links": {
197 "parent": {
198 "href": "/api/v2/teams",
199 "type": "application/json"
200 },
201 "roles": {
202 "href": "/api/v2/teams/example-team/roles",
203 "type": "application/json"
204 },
205 "self": {
206 "href": "/api/v2/teams/example-team",
207 "type": "application/json"
208 }
209 }
210 },
211 "archivedDate": 1494437420312,
212 "deprecated": false,
213 "deprecatedDate": 1494437420312,
214 "defaults": {
215 "onVariation": 0,
216 "offVariation": 1
217 },
218 "_purpose": "string",
219 "migrationSettings": {
220 "contextKind": "device",
221 "stageCount": 6
222 },
223 "environments": {
224 "my-environment": {
225 "on": false,
226 "archived": false,
227 "salt": "61eddeadbeef4da1facecafe3a60a397",
228 "sel": "810edeadbeef4844facecafe438f2999492",
229 "lastModified": 1627071171347,
230 "version": 1,
231 "_site": {
232 "href": "/default/my-environment/features/client-side-flag",
233 "type": "text/html"
234 },
235 "_environmentName": "My Environment",
236 "trackEvents": false,
237 "trackEventsFallthrough": false,
238 "targets": [
239 {
240 "values": [
241 "user-key-123abc"
242 ],
243 "variation": 0,
244 "contextKind": "user"
245 }
246 ],
247 "contextTargets": [
248 {
249 "values": [
250 "device-key-123abc"
251 ],
252 "variation": 0,
253 "contextKind": "device"
254 }
255 ],
256 "rules": [],
257 "fallthrough": {
258 "variation": 0
259 },
260 "offVariation": 1,
261 "prerequisites": [],
262 "_summary": {
263 "variations": {
264 "0": {
265 "rules": 0,
266 "nullRules": 0,
267 "targets": 1,
268 "contextTargets": 1,
269 "isFallthrough": true
270 },
271 "1": {
272 "rules": 0,
273 "nullRules": 0,
274 "targets": 0,
275 "isOff": true
276 }
277 },
278 "prerequisites": 0
279 }
280 }
281 },
282 "includeInSnippet": true,
283 "goalIds": []
284}
Create a feature flag with the given name, key, and variations. <details> <summary>Click to expand instructions for <strong>creating a migration flag</strong></summary> ### 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: ```json { "key": "flag-key-123", "purpose": "migration", "migrationSettings": { "stageCount": 6, "contextKind": "account" } } ``` To learn more, read [Migration Flags](https://launchdarkly.com/docs/home/flags/migration). </details>
Was this page helpful?
Previous

Delete feature flag

Next
Built with

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

Click to expand instructions for creating a migration flag

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:

1{
2 "key": "flag-key-123",
3 "purpose": "migration",
4 "migrationSettings": {
5 "stageCount": 6,
6 "contextKind": "account"
7 }
8}

To learn more, read Migration Flags.

Authentication

Authorizationstring
API Key authentication via header

Path parameters

projectKeystringRequiredformat: "string"
The project key

Query parameters

clonestringOptionalformat: "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.

Request

This endpoint expects an object.
namestringRequired

A human-friendly name for the feature flag

keystringRequired
A unique key used to reference the flag in your code
descriptionstringOptional
Description of the feature flag. Defaults to an empty string.
clientSideAvailabilityobjectOptional

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

variationslist of objectsOptional

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.

temporarybooleanOptional

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

tagslist of stringsOptional
Tags for the feature flag. Defaults to an empty array.
customPropertiesmap from strings to objectsOptional
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.
defaultsobjectOptional
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.
purposeenumOptional
Purpose of the flag
Allowed values:
migrationSettingsobjectOptional

Settings relevant to flags where purpose is migration

maintainerIdstringOptional
The ID of the member who maintains this feature flag
maintainerTeamKeystringOptional
The key of the team that maintains this feature flag
initialPrerequisiteslist of objectsOptional
Initial set of prerequisite flags for all environments
isFlagOnbooleanOptional

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

includeInSnippetbooleanOptionalDeprecated

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

Response

Global flag response
namestring

A human-friendly name for the feature flag

kindenum
Kind of feature flag
Allowed values:
keystring
A unique key used to reference the flag in your code
_versioninteger
Version of the feature flag
creationDatelong
Timestamp of flag creation date
variationslist of objects
An array of possible variations for the flag
temporaryboolean
Whether the flag is a temporary flag
tagslist of strings
Tags for the feature flag
_linksmap from strings to objects
The location and content type of related resources
experimentsobject
Experimentation data for the feature flag
customPropertiesmap from strings to objects
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.
archivedboolean
Boolean indicating if the feature flag is archived
descriptionstring
Description of the feature flag
clientSideAvailabilityobject

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

maintainerIdstring
Associated maintainerId for the feature flag
_maintainerobject
Associated maintainer member info for the feature flag
maintainerTeamKeystring
The key of the associated team that maintains this feature flag
_maintainerTeamobject
Associated maintainer team info for the feature flag
archivedDatelong
If archived is true, date of archive
deprecatedboolean
Boolean indicating if the feature flag is deprecated
deprecatedDatelong
If deprecated is true, date of deprecation
defaultsobject
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.
_purposestring
migrationSettingsobject

Migration-related settings for the flag

environmentsmap from strings to objects

Details on the environments for this flag. Only returned if the request is filtered by environment, using the filterEnv query parameter.

includeInSnippetbooleanDeprecated

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

goalIdslist of stringsDeprecated

Deprecated, use experiments instead

Errors

400
Bad Request Error
401
Unauthorized Error
409
Conflict Error
429
Too Many Requests Error