Feature flags
The feature flags API allows you to list, create, and modify feature flags and their targeting. For example, you can control percentage rollouts, target specific contexts, or even toggle off a feature flag programmatically.
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. To learn more, read Using feature flags.
Click to expand an example of a complete feature flag representation
Anatomy of a feature flag
This section describes the sample feature flag representation in more detail.
Top-level attributes
Most of the top-level attributes have a straightforward interpretation, for example name
and description
.
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.
To update these attributes, read Update feature flag, especially the instructions for updating flag settings.
Per-environment configurations
Each entry in the environments
map contains a JSON object that represents the environment-specific flag configuration data available in the flag’s targeting page. To learn more, read Targeting with flags.
To update per-environment information for a flag, read Update feature flag, especially the instructions for turning flags on and off and working with targeting and variations.
Individual context targets
The targets
and contextTargets
arrays in the per-environment configuration data correspond to the individual context targeting on the flag’s targeting page. To learn more, read Individual targeting.
Each object in the targets
and contextTargets
arrays represents a list of context keys assigned to a particular variation. The targets
array includes contexts with contextKind
of “user” and the contextTargets
array includes contexts with context kinds other than “user.”
For example:
The targets
array means that any user context instance with the key user-key-123abc
receives the first variation listed in the variations
array. The contextTargets
array means that any organization context with the key org-key-123abc
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, both contexts are receiving the true
variation.
Targeting rules
The rules
array corresponds to the rules section of the flag’s targeting page. This is where you can express complex rules on attributes with conditions and operators. For example, you might create a rule that specifies “roll out the true
variation to 80% of contexts whose email address ends with gmail.com
”. To learn more, read Targeting rules.
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. In the LaunchDarkly UI, it is called the “Default rule.”
The off variation
The off variation represents the variation to serve if the feature flag targeting 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
When you work with targeting rules and with the default rule, you can specify either a single variation or a percentage rollout. 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 60000
means that 60% of contexts will receive that variation. The sum of weights across all variations should be 100%.