Feature flags

Anatomy of a feature flag

The feature flag API allows you to control percentage rollouts, target specific users, or even toggle off a feature programmatically. By looking at the representation of a feature flag, we can see how to do any of these tasks.

Sample feature flag representation

Every feature flag has a set of top-level attributes, as well as an environments map containing the flag rollout and targeting rules specific to each environment. Top-level attributes include things like the flag's name, description, tags, and creation date.

For reference, here's a complete feature flag representation. Below we break this down and explain each attribute in detail.

{
  "name": "Alternate product page",
  "kind": "boolean",
  "description": "This is a description",
  "key": "alternate.page",
  "creationDate": 1418684722483,
  "includeInSnippet": true,
  "variations": [
    {
      "value": true,
      "name": "true"
    },
    {
      "value": false,
      "name": "false"
    }
  ],
  "defaults": {
    "onVariation": 0,
    "offVariation": 1
  },
  "temporary": false,
  "tags": ["ops", "experiments"],
  "_links": {
    "parent": {
      "href": "/api/v2/flags/default",
      "type": "application/json"
    },
    "self": {
      "href": "/api/v2/flags/default/alternate.page",
      "type": "application/json"
    }
  },
  "maintainerId": "548f6741c1efad40031b18ae",
  "_maintainer": {
    "_links": {
      "parent": {
        "href": "/internal/account/members",
        "type": "application/json"
      },
      "self": {
        "href": "/internal/account/members/548f6741c1efad40031b18ae",
        "type": "application/json"
      }
    },
    "_id": "548f6741c1efad40031b18ae",
    "firstName": "Reese",
    "lastName": "App",
    "role": "owner",
    "email": "refapp@launchdarkly.com",
    "_pendingInvite": false,
    "isBeta": false,
    "customRoles": []
  },
  "goalIds": [],
  "environments": {
    "production": {
      "on": true,
      "archived": false,
      "salt": "YWx0ZXJuYXRlLnBhZ2U=",
      "sel": "45501b9314dc4641841af774cb038b96",
      "lastModified": 1469326565348,
      "version": 61,
      "targets": [
        {
          "values": ["1461797806427-7-115540266"],
          "variation": 0
        },
        {
          "values": ["Gerhard.Little@yahoo.com"],
          "variation": 1
        }
      ],
      "rules": [
        {
          "variation": 0,
          "clauses": [
            {
              "attribute": "groups",
              "op": "in",
              "values": ["Top Customers"],
              "negate": false
            },
            {
              "attribute": "email",
              "op": "endsWith",
              "values": ["gmail.com"],
              "negate": false
            }
          ]
        }
      ],
      "fallthrough": {
        "rollout": {
          "variations": [
            {
              "variation": 0,
              "weight": 60000
            },
            {
              "variation": 1,
              "weight": 40000
            }
          ]
        }
      },
      "offVariation": 1,
      "prerequisites": [],
      "_site": {
        "href": "/default/production/features/alternate.page",
        "type": "text/html"
      }
    },
    "test": {
      "on": true,
      "archived": false,
      "salt": "YWx0ZXJuYXRlLnBhZ2U=",
      "sel": "76c63094d35949bb9dc9bd5c570bacf5",
      "lastModified": 1455145480896,
      "version": 37,
      "targets": [
        {
          "values": [],
          "variation": 0
        },
        {
          "values": [],
          "variation": 1
        }
      ],
      "rules": [],
      "fallthrough": {
        "rollout": {
          "variations": [
            {
              "variation": 0,
              "weight": 49000
            },
            {
              "variation": 1,
              "weight": 51000
            }
          ]
        }
      },
      "prerequisites": [],
      "_site": {
        "href": "/default/tester/features/alternate.page",
        "type": "text/html"
      }
    }
  }
}

Top-level attributes

Most of the top-level attributes have a straightforward interpretation. For example, to change the name of a feature, update the feature flag with the name attribute set to the new name:

[
    { "op": "replace", "path": "/name", "value": "New name" }
]

The variations array represents the different variation values that a feature flag has. For a boolean flag, there are two variations: true and false. Multivariate flags have more variation values, and those values could be any JSON type: numbers, strings, objects, or arrays. In targeting rules, the variations are referred to by their index into this array. Below are some specific examples.

Per-environment configurations

Each entry in the environments map contains a JSON object that represents the environment-specific flag configuration data that you see on the Targeting tab of your Manage Feature page. For example, to toggle off a feature flag in your production environment, use the following JSON patch operation:

[
    { "op": "replace", "path": "/environments/production/on", "value": false }
]

Each section of the Targeting tab corresponds to a different attribute of the per-environment configuration data, as shown here:

Individual user targets

The targets array in the per-environment configuration data represents the individual user targeting rules on the Targeting tab. Each object in the targets array represents a list of user keys assigned to a particular variation. For example:

{
    ...
    "environments" : {
        "production" : {
            ...
            "targets": [
                {
                    "values": ["foo@example.com"],
                    "variation: 0
                }
            ]
        }
    }
}

This targets array here means that user foo@example.com receives the first variation listed in the variations array. Recall that the variations are stored at the top level of the flag JSON in an array, and the per-environment configuration rules point to indexes into this array. If this is a boolean flag, foo@example.com is receiving the true variation.

Targeting rules

The rules array corresponds to the custom targeting rules section of the Targeting tab. This is where you can express complex rules on attributes with conditions and operators. For example, a rule like "roll out the true variation to 80% of users whose email address ends with gmail.com could be expressed here.

The fallthrough rule

The fallthrough object is a special rule that contains no conditions. It is the rollout strategy that is applied when none of the individual or custom targeting rules match.

The off variation

The off variation represents the variation to serve if the feature flag is turned off, meaning the on attribute is false. For boolean flags, this is usually false. For multivariate flags, set the off variation to whatever variation represents the control or baseline behavior for your application. If you don't set the off variation, LaunchDarkly will serve the fallback value defined in your code.

Percentage rollouts

The weight attribute defines the percentage rollout for each variation. Weights range from 0 (a 0% rollout) to 100000 (a 100% rollout). The weights are scaled by a factor of 1000 so that fractions of a percent can be represented without using floating-point. For example, a weight of 50000 means that 50% of users that don't otherwise match any targets will see that variation. The sum of weights across all variations should be 100%.

Get flag status across environments

Get the status for a particular feature flag across environments.

Request
Security:
ApiKey (readwrite)
path Parameters
projKey
required
string <string>

The project key

key
required
string <string>

The feature flag key

query Parameters
env
string <string>

Optional environment filter

Responses
200

Flag status across environments response

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/flag-status/{projKey}/{key}
Request samples
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/flag-status/:projKey/:key \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "environments": {
    },
  • "key": "my-flag",
  • "_links": {
    }
}

List feature flag statuses

Get a list of statuses for all feature flags. The status includes the last time the feature flag was requested, as well as a state, which is one of the following:

  • new: the feature flag was created within the last seven days, and has not been requested yet
  • active: the feature flag was requested by your servers or clients within the last seven days
  • inactive: the feature flag was created more than seven days ago, and hasn't been requested by your servers or clients within the past seven days
  • launched: one variation of the feature flag has been rolled out to all your users for at least 7 days
Request
Security:
ApiKey (readwrite)
path Parameters
projKey
required
string <string>

The project key

envKey
required
string <string>

Filter configurations by environment

Responses
200

Flag Statuses collection response

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/flag-statuses/{projKey}/{envKey}
Request samples
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/flag-statuses/:projKey/:envKey \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "_links": {
    },
  • "items": [
    ]
}

Get feature flag status

Get the status for a particular feature flag.

Request
Security:
ApiKey (readwrite)
path Parameters
projKey
required
string <string>

The project key

envKey
required
string <string>

The environment key

key
required
string <string>

The feature flag key

Responses
200

Flag status response

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/flag-statuses/{projKey}/{envKey}/{key}
Request samples
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/flag-statuses/:projKey/:envKey/:key \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "_links": {
    },
  • "name": "inactive",
  • "lastRequested": "2020-02-05T18:17:01.514Z",
  • "default": null
}

List feature flags

Get a list of all features in the given project. By default, each feature includes configurations for each environment. You can filter environments with the env query parameter. For example, setting env=production restricts the returned configurations to just your production environment. You can also filter feature flags by tag with the tag query parameter.

We support the following fields for filters:

  • query is a string that matches against the flags' keys and names. It is not case sensitive.
  • archived is a boolean to filter the list to archived flags. When this is absent, only unarchived flags are returned.
  • type is a string allowing filtering to temporary or permanent flags.
  • status is a string allowing filtering to new, inactive, active, or launched flags in the specified environment. This filter also requires a filterEnv field to be set to a valid environment. For example: filter=status:active,filterEnv:production.
  • tags is a + separated list of tags. It filters the list to members who have all of the tags in the list.
  • hasExperiment is a boolean with values of true or false and returns any flags that have an attached metric.
  • hasDataExport is a boolean with values of true or false and returns any flags that are currently exporting data in the specified environment. This includes flags that are exporting data via Experimentation. This filter also requires a filterEnv field to be set to a valid environment key. e.g. filter=hasExperiment:true,filterEnv:production
  • evaluated is an object that contains a key of after and a value in Unix time in milliseconds. This returns all flags that have been evaluated since the time you specify in the environment provided. This filter also requires a filterEnv field to be set to a valid environment. For example: filter=evaluated:{"after": 1590768455282},filterEnv:production.
  • filterEnv is a string with the key of a valid environment. The filterEnv field is used for filters that are environment specific. If there are multiple environment specific filters you should only declare this parameter once. For example: filter=evaluated:{"after": 1590768455282},filterEnv:production,status:active.

An example filter is query:abc,tags:foo+bar. This matches flags with the string abc in their key or name, ignoring case, which also have the tags foo and bar.

By default, this 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.

Request
Security:
ApiKey (readwrite)
path Parameters
projKey
required
string <string>

The project key

query Parameters
env
string <string>

Filter configurations by environment

tag
string <string>

Filter feature flags by tag

limit
integer <int64>

The number of feature flags to return. Defaults to -1, which returns all flags

offset
integer <int64>

Where to start in the list. Use this with pagination. For example, an offset of 10 skips the first ten items and then returns the next limit items

query
string <string>

A string that matches against the flags' keys and names. It is not case sensitive

archived
boolean <boolean>

A boolean to filter the list to archived flags. When this is absent, only unarchived flags will be returned

summary
boolean <boolean>

By default in API version >= 1, flags will not include their list of prerequisites, targets or rules. Set summary=0 to include these fields for each flag returned

filter
string <string>

A comma-separated list of filters. Each filter is of the form field:value

sort
string <string>

A comma-separated list of fields to sort by. Fields prefixed by a dash ( - ) sort in descending order

Responses
200

Global flags collection response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/flags/{projKey}
Request samples
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/flags/:projKey \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "items": [
    ],
  • "_links": {
    },
  • "totalCount": 1
}

Create a feature flag

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

Request
Security:
ApiKey (readwrite)
path Parameters
projKey
required
string <string>

The project key.

query Parameters
clone
string <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 Body schema: application/json
name
required
string

A human-friendly name for the feature flag

key
required
string

A unique key to reference the flag in your code

description
string

Description of the feature flag

includeInSnippet
boolean

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

object (ClientSideAvailabilityPost)
Array of objects (Variation)

An array of possible variations for the flag

variationJsonSchema
any
temporary
boolean

Whether or not the flag is a temporary flag

tags
Array of strings

Tags for the feature flag

object (CustomProperties)
object (Defaults)
Responses
201

Global flag response

400

Invalid request

401

Invalid access token

409

Status conflict

429

Rate limited

post/api/v2/flags/{projKey}
Request samples
application/json
{
  • "key": "my-flag",
  • "name": "My Flag"
}
Response samples
application/json
{
  • "name": "My Flag",
  • "kind": "boolean",
  • "description": "string",
  • "key": "my-flag",
  • "_version": 1,
  • "creationDate": 0,
  • "includeInSnippet": true,
  • "clientSideAvailability": {
    },
  • "variations": [
    ],
  • "variationJsonSchema": null,
  • "temporary": true,
  • "tags": [ ],
  • "_links": {
    },
  • "maintainerId": "569f183514f4432160000007",
  • "_maintainer": {
    },
  • "goalIds": [ ],
  • "experiments": {
    },
  • "customProperties": {
    },
  • "archived": false,
  • "archivedDate": 0,
  • "defaults": {
    },
  • "environments": {
    }
}

Copy feature flag

The includedActions and excludedActions define the parts of the flag configuration that are copied or not copied. By default, the entire flag configuration is copied.

You can have either includedActions or excludedActions but not both.

Valid includedActions and excludedActions include:

  • updateOn
  • updatePrerequisites
  • updateTargets
  • updateRules
  • updateFallthrough
  • updateOffVariation

The source and target must be JSON objects if using curl, specifying the environment key and (optional) current flag configuration version in that environment. For example:

{
  "key": "production",
  "currentVersion": 3
}

If target is specified as above, the API will test to ensure that the current flag version in the production environment is 3, and reject attempts to copy settings to production otherwise. You can use this to enforce optimistic locking on copy attempts.

Request
Security:
ApiKey (readwrite)
path Parameters
projKey
required
string <string>

The project key.

featureFlagKey
required
string <string>

The feature flag's key. The key identifies the flag in your code.

Request Body schema: application/json
required
object (FlagCopyConfigEnvironment)
required
object (FlagCopyConfigEnvironment)
comment
string
includedActions
Array of strings
Items Enum: "updateOn" "updateRules" "updateFallthrough" "updateOffVariation" "updatePrerequisites" "updateTargets"
excludedActions
Array of strings
Items Enum: "updateOn" "updateRules" "updateFallthrough" "updateOffVariation" "updatePrerequisites" "updateTargets"
Responses
201

Global flag response

400

Invalid request

401

Invalid access token

405

Method not allowed

409

Status conflict

429

Rate limited

post/api/v2/flags/{projKey}/{featureFlagKey}/copy
Request samples
application/json
{
  • "source": {
    },
  • "target": {
    },
  • "comment": "string",
  • "includedActions": [
    ],
  • "excludedActions": [
    ]
}
Response samples
application/json
{
  • "name": "My Flag",
  • "kind": "boolean",
  • "description": "string",
  • "key": "my-flag",
  • "_version": 1,
  • "creationDate": 0,
  • "includeInSnippet": true,
  • "clientSideAvailability": {
    },
  • "variations": [
    ],
  • "variationJsonSchema": null,
  • "temporary": true,
  • "tags": [ ],
  • "_links": {
    },
  • "maintainerId": "569f183514f4432160000007",
  • "_maintainer": {
    },
  • "goalIds": [ ],
  • "experiments": {
    },
  • "customProperties": {
    },
  • "archived": false,
  • "archivedDate": 0,
  • "defaults": {
    },
  • "environments": {
    }
}

Get expiring user targets for feature flag

Get a list of user targets on a feature flag that are scheduled for removal.

Request
Security:
ApiKey (readwrite)
path Parameters
projKey
required
string <string>

The project key.

envKey
required
string <string>

The environment key.

flagKey
required
string <string>

The feature flag key.

Responses
200

User targeting expirations on feature flag response.

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/flags/{projKey}/{flagKey}/expiring-user-targets/{envKey}
Request samples
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/flags/:projKey/:flagKey/expiring-user-targets/:envKey \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "items": [
    ],
  • "_links": {
    }
}

Update expiring user targets on feature flag

Update the list of user targets on a feature flag that are scheduled for removal.

Request
Security:
ApiKey (readwrite)
path Parameters
projKey
required
string <string>

The project key.

envKey
required
string <string>

The environment key.

flagKey
required
string <string>

The feature flag key.

Request Body schema: application/json
required
Array of objects (JSONPatch)
comment
string
Responses
200

User targeting expirations on feature flag response.

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

patch/api/v2/flags/{projKey}/{flagKey}/expiring-user-targets/{envKey}
Request samples
application/json
{
  • "patch": [
    ],
  • "comment": "string"
}
Response samples
application/json
{
  • "items": [
    ],
  • "_links": {
    },
  • "totalInstructions": 0,
  • "successfulInstructions": 0,
  • "failedInstructions": 0,
  • "errors": [
    ]
}

Get feature flag

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.

Request
Security:
ApiKey (readwrite)
path Parameters
projKey
required
string <string>

The project key

key
required
string <string>

The feature flag key

query Parameters
env
string <string>

Filter configurations by environment

Responses
200

Global flag response

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/flags/{projKey}/{key}
Request samples
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/flags/:projKey/:key \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "name": "My Flag",
  • "kind": "boolean",
  • "description": "string",
  • "key": "my-flag",
  • "_version": 1,
  • "creationDate": 0,
  • "includeInSnippet": true,
  • "clientSideAvailability": {
    },
  • "variations": [
    ],
  • "variationJsonSchema": null,
  • "temporary": true,
  • "tags": [ ],
  • "_links": {
    },
  • "maintainerId": "569f183514f4432160000007",
  • "_maintainer": {
    },
  • "goalIds": [ ],
  • "experiments": {
    },
  • "customProperties": {
    },
  • "archived": false,
  • "archivedDate": 0,
  • "defaults": {
    },
  • "environments": {
    }
}

Update feature flag

Perform a partial update to a feature flag.

Using JSON Patches on a feature flag

When using the update feature flag endpoint to add individual users to a specific variation, there are two different patch documents, depending on whether users are already being individually targeted for the variation.

If a flag variation already has users individually targeted, the path for the JSON Patch operation is:

{
  "op": "add",
  "path": "/environments/devint/targets/0/values/-",
  "value": "TestClient10"
}

If a flag variation does not already have users individually targeted, the path for the JSON Patch operation is:

[
  {
    "op": "add",
    "path": "/environments/devint/targets/-",
    "value": { "variation": 0, "values": ["TestClient10"] }
  }
]

Using semantic patches on a feature flag

To use a semantic patch on a feature flag resource, you must include a header in the request. If you call a semantic patch resource without this header, you receive a 400 response as your semantic patch will be interpreted as a JSON patch.

Use this header:

Content-Type: application/json; domain-model=launchdarkly.semanticpatch

The body of a semantic patch request takes the following three properties:

  1. comment string: (Optional) A description of the update.
  2. environmentKey string: (Required) The key of the LaunchDarkly environment.
  3. instructions array: (Required) The action or list of actions to be performed by the update. Each update action in the list must be an object/hash table with a kind property, although depending on the action, other properties may be necessary. Read below for more information on the specific supported semantic patch instructions.

If any instruction in the patch encounters an error, the error will be returned and the flag will not be changed. In general, instructions will silently do nothing if the flag is already in the state requested by the patch instruction. For example, removeUserTargets does nothing when the targets have already been removed). They will generally error if a parameter refers to something that does not exist, like a variation ID that doesn't correspond to a variation on the flag or a rule ID that doesn't belong to a rule on the flag. Other specific error conditions are noted in the instruction descriptions.

Instructions

turnFlagOn

Sets the flag's targeting state to on.

turnFlagOff

Sets the flag's targeting state to off.

addUserTargets

Adds the user keys in values to the individual user targets for the variation specified by variationId. Returns an error if this causes the same user key to be targeted in multiple variations.

Parameters
  • values: list of user keys
  • variationId: ID of a variation on the flag

removeUserTargets

Removes the user keys in values to the individual user targets for the variation specified by variationId. Does nothing if the user keys are not targeted.

Parameters
  • values: list of user keys
  • variationId: ID of a variation on the flag

replaceUserTargets

Completely replaces the existing set of user targeting. All variations must be provided. Example:

{
  "kind": "replaceUserTargets",
  "targets": [
    {
      "variationId": "variation-1",
      "values": ["blah", "foo", "bar"]
    },
    {
      "variationId": "variation-2",
      "values": ["abc", "def"]
    }
  ]
}
Parameters
  • targets: a list of user targeting

clearUserTargets

Removes all individual user targets from the variation specified by variationId

Parameters
  • variationId: ID of a variation on the flag

addPrerequisite

Adds the flag indicated by key with variation variationId as a prerequisite to the flag.

Parameters
  • key: flag key of another flag
  • variationId: ID of a variation of the flag with key key

removePrerequisite

Removes the prerequisite indicated by key. Does nothing if this prerequisite does not exist.

Parameters
  • key: flag key of an existing prerequisite

updatePrerequisite

Changes the prerequisite with flag key key to the variation indicated by variationId. Returns an error if this prerequisite does not exist.

Parameters
  • key: flag key of an existing prerequisite
  • variationId: ID of a variation of the flag with key key

replacePrerequisites

Completely replaces the existing set of prerequisites for a given flag. Example:

{
  "kind": "replacePrerequisites",
  "prerequisites": [
    {
      "key": "flag-key",
      "variationId": "variation-1"
    },
    {
      "key": "another-flag",
      "variationId": "variation-2"
    }
  ]
}
Parameters
  • prerequisites: a list of prerequisites

addRule

Adds a new rule to the flag with the given clauses which serves the variation indicated by variationId or the percent rollout indicated by rolloutWeights and rolloutBucketBy. If beforeRuleId is set, the rule will be added in the list of rules before the indicated rule. Otherwise, the rule will be added to the end of the list.

Parameters
  • clauses: Array of clauses (see addClauses)
  • beforeRuleId: Optional ID of a rule in the flag
  • variationId: ID of a variation of the flag
  • rolloutWeights: Map of variationId to weight in thousandths of a percent (0-100000)
  • rolloutBucketBy: Optional user attribute

removeRule

Removes the targeting rule specified by ruleId. Does nothing if the rule does not exist.

Parameters
  • ruleId: ID of a rule in the flag

replaceRules

Completely replaces the existing rules for a given flag. Example:

{
  "kind": "replaceRules",
  "rules": [
    {
      "variationId": "variation-1",
      "description": "myRule",
      "clauses": [
        {
          "attribute": "segmentMatch",
          "op": "segmentMatch",
          "values": ["test"]
        }
      ],
      "trackEvents": true
    }
  ]
}
Parameters
  • rules: a list of rules

addClauses

Adds the given clauses to the rule indicated by ruleId.

Parameters
  • ruleId: ID of a rule in the flag
  • clauses: Array of clause objects, with attribute (string), op (string), and values (array of strings, numbers, or dates) properties.

removeClauses

Removes the clauses specified by clauseIds from the rule indicated by ruleId.

Parameters

  • ruleId: ID of a rule in the flag
  • clauseIds: Array of IDs of clauses in the rule

updateClause

Replaces the clause indicated by ruleId and clauseId with clause.

Parameters
  • ruleId: ID of a rule in the flag
  • clauseId: ID of a clause in that rule
  • clause: Clause object

addValuesToClause

Adds values to the values of the clause indicated by ruleId and clauseId.

Parameters
  • ruleId: ID of a rule in the flag
  • clauseId: ID of a clause in that rule
  • values: Array of strings

removeValuesFromClause

Removes values from the values of the clause indicated by ruleId and clauseId.

Parameters

ruleId: ID of a rule in the flag clauseId: ID of a clause in that rule values: Array of strings

reorderRules

Rearranges the rules to match the order given in ruleIds. Will return an error if ruleIds does not match the current set of rules on the flag.

Parameters
  • ruleIds: Array of IDs of all rules in the flag

updateRuleVariationOrRollout

Updates what the rule indicated by ruleId serves if its clauses evaluate to true. Can either be a fixed variation indicated by variationId or a percent rollout indicated by rolloutWeights and rolloutBucketBy.

Parameters
  • ruleId: ID of a rule in the flag
  • variationId: ID of a variation of the flag or
  • rolloutWeights: Map of variationId to weight in thousandths of a percent (0-100000)
  • rolloutBucketBy: Optional user attribute

updateFallthroughVariationOrRollout

Updates the flag's fallthrough, which is served if none of the targeting rules match. Can either be a fixed variation indicated by variationId or a percent rollout indicated by rolloutWeights and rolloutBucketBy.

Parameters

variationId: ID of a variation of the flag or rolloutWeights: Map of variationId to weight in thousandths of a percent (0-100000) rolloutBucketBy: Optional user attribute

updateOffVariation

Updates the variation served when the flag's targeting is off to the variation indicated by variationId.

Parameters

variationId: ID of a variation of the flag

Example

{
  "environmentKey": "production",
  "instructions": [
    {
      "kind": "turnFlagOn"
    },
    {
      "kind": "turnFlagOff"
    },
    {
      "kind": "addUserTargets",
      "variationId": "8bfb304e-d516-47e5-8727-e7f798e8992d",
      "values": ["userId", "userId2"]
    },
    {
      "kind": "removeUserTargets",
      "variationId": "8bfb304e-d516-47e5-8727-e7f798e8992d",
      "values": ["userId3", "userId4"]
    },
    {
      "kind": "updateFallthroughVariationOrRollout",
      "rolloutWeights": {
        "variationId": 50000,
        "variationId2": 50000
      },
      "rolloutBucketBy": null
    },
    {
      "kind": "addRule",
      "clauses": [
        {
          "attribute": "segmentMatch",
          "negate": false,
          "values": ["test-segment"]
        }
      ],
      "variationId": null,
      "rolloutWeights": {
        "variationId": 50000,
        "variationId2": 50000
      },
      "rolloutBucketBy": "key"
    },
    {
      "kind": "removeRule",
      "ruleId": "99f12464-a429-40fc-86cc-b27612188955"
    },
    {
      "kind": "reorderRules",
      "ruleIds": ["2f72974e-de68-4243-8dd3-739582147a1f", "8bfb304e-d516-47e5-8727-e7f798e8992d"]
    },
    {
      "kind": "addClauses",
      "ruleId": "1134",
      "clauses": [
        {
          "attribute": "email",
          "op": "in",
          "negate": false,
          "values": ["test@test.com"]
        }
      ]
    },
    {
      "kind": "removeClauses",
      "ruleId": "1242529",
      "clauseIds": ["8bfb304e-d516-47e5-8727-e7f798e8992d"]
    },
    {
      "kind": "updateClause",
      "ruleId": "2f72974e-de68-4243-8dd3-739582147a1f",
      "clauseId": "309845",
      "clause": {
        "attribute": "segmentMatch",
        "negate": false,
        "values": ["test-segment"]
      }
    },
    {
      "kind": "updateRuleVariationOrRollout",
      "ruleId": "2342",
      "rolloutWeights": null,
      "rolloutBucketBy": null
    },
    {
      "kind": "updateOffVariation",
      "variationId": "3242453"
    },
    {
      "kind": "addPrerequisite",
      "variationId": "234235",
      "key": "flagKey2"
    },
    {
      "kind": "updatePrerequisite",
      "variationId": "234235",
      "key": "flagKey2"
    },
    {
      "kind": "removePrerequisite",
      "key": "flagKey"
    }
  ]
}

Using JSON patches on a feature flag

If you do not include the header described above, you can use JSON patch.

Request
Security:
ApiKey (readwrite)
path Parameters
projKey
required
string <string>

The project key.

key
required
string <string>

The feature flag's key. The key identifies the flag in your code.

Request Body schema: application/json
required
Array of objects (JSONPatch)
comment
string
Responses
200

Global flag response

400

Invalid request

401

Invalid access token

404

Invalid resource identifier

409

Status conflict

429

Rate limited

patch/api/v2/flags/{projKey}/{key}
Request samples
application/json
{
  • "patch": [
    ],
  • "comment": "string"
}
Response samples
application/json
{
  • "name": "My Flag",
  • "kind": "boolean",
  • "description": "string",
  • "key": "my-flag",
  • "_version": 1,
  • "creationDate": 0,
  • "includeInSnippet": true,
  • "clientSideAvailability": {
    },
  • "variations": [
    ],
  • "variationJsonSchema": null,
  • "temporary": true,
  • "tags": [ ],
  • "_links": {
    },
  • "maintainerId": "569f183514f4432160000007",
  • "_maintainer": {
    },
  • "goalIds": [ ],
  • "experiments": {
    },
  • "customProperties": {
    },
  • "archived": false,
  • "archivedDate": 0,
  • "defaults": {
    },
  • "environments": {
    }
}

Delete feature flag

Delete a feature flag in all environments. Use with caution: only delete feature flags your application no longer uses.

Request
Security:
ApiKey (readwrite)
path Parameters
projKey
required
string <string>

The project key.

key
required
string <string>

The feature flag's key. The key identifies the flag in your code.

Responses
204

Action succeeded

401

Invalid access token

404

Invalid resource identifier

429

Rate limited

delete/api/v2/flags/{projKey}/{key}
Request samples
curl -i -X DELETE \
  https://app.launchdarkly.com/api/v2/flags/:projKey/:key \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "code": "unauthorized",
  • "message": "invalid key"
}