2021-02-25 16:01:36 +01:00
---
2023-10-02 19:37:53 +02:00
title: How to create a feature flag
2021-02-25 16:01:36 +01:00
---
2024-05-24 12:28:49 +02:00
:::info Feature flags or feature flags?
2023-10-02 19:37:53 +02:00
2024-05-24 12:28:49 +02:00
This document uses **feature flags** and **feature flags** interchangeably. Some people prefer flag; others prefer flag. We use both - they are synonyms for us.
2023-10-02 19:37:53 +02:00
:::
2024-05-24 12:28:49 +02:00
Feature Flags (or [Feature flags ](../reference/feature-toggles.mdx ) in the UI) are the foundation of Unleash. They are at the core of everything we do and are a fundamental building block in any feature management system. This guide shows you how to create feature flags in Unleash and how to add any optional constraints, segments, variants, and more. Links to learn more about these concepts will be scattered throughout the text.
2021-02-25 16:01:36 +01:00
2022-06-17 12:36:19 +02:00
You can perform every action both via the UI and the admin API. This guide includes screenshots to highlight the relevant UI controls and links to the relevant API methods for each step.
2021-02-25 16:01:36 +01:00
2022-06-17 12:36:19 +02:00
This guide is split into three sections:
2022-06-22 12:49:18 +02:00
2023-10-02 19:37:53 +02:00
1. [Prerequisites ](#prerequisites ): you need these before you can create a flag.
2. [Required steps ](#required-steps ): all the required steps to create a flag and activate it in production.
3. [Optional steps ](#optional-steps ): optional steps you can take to further target and configure your feature flag and its audience.
2021-02-25 16:01:36 +01:00
2022-06-17 12:36:19 +02:00
## Prerequisites
2021-02-25 16:01:36 +01:00
2023-02-27 12:49:53 +01:00
To perform all the steps in this guide, you will need:
2022-06-22 12:49:18 +02:00
2022-06-17 12:36:19 +02:00
- A running Unleash instance
2023-10-02 19:37:53 +02:00
- A project to hold the flag
2022-06-17 12:36:19 +02:00
- A user with an **editor** or **admin** role OR a user with the following permissions inside the target project:
2023-02-27 12:49:53 +01:00
- **[project-level permissions](../reference/rbac.md#project-permissions)**
2024-05-24 12:28:49 +02:00
- create feature flags
2023-02-27 12:49:53 +01:00
- **[environment-level permissions](../reference/rbac.md#environment-permissions)**
- create/edit variants[^1]
- create activation strategies
- update activation strategies
2024-05-24 12:28:49 +02:00
- enable/disable flags
2021-02-25 16:01:36 +01:00
2022-06-17 12:36:19 +02:00
:::info roles
2021-02-25 16:01:36 +01:00
refactor: move docs into new structure / fix links for SEO (#2416)
## What
This (admittedly massive) PR updates the "physical" documentation
structure and fixes url inconsistencies and SEO problems reported by
marketing. The main points are:
- remove or move directories : advanced, user_guide, deploy, api
- move the files contained within to the appropriate one of topics,
how-to, tutorials, or reference
- update internal doc links and product links to the content
- create client-side redirects for all the urls that have changed.
A number of the files have been renamed in small ways to better match
their url and to make them easier to find. Additionally, the top-level
api directory has been moved to /reference/api/legacy/unleash (see the
discussion points section for more on this).
## Why
When moving our doc structure to diataxis a while back, we left the
"physical' files lying where they were, because it didn't matter much to
the new structure. However, that did introduce some inconsistencies with
where you place docs and how we organize them.
There's also the discrepancies in whether urls us underscores or hyphens
(which isn't necessarily the same as their file name), which has been
annoying me for a while, but now has also been raised by marketing as an
issue in terms of SEO.
## Discussion points
The old, hand-written API docs have been moved from /api to
/reference/api/legacy/unleash. There _is_ a /reference/api/unleash
directory, but this is being populated by the OpenAPI plugin, and mixing
those could only cause trouble. However, I'm unsure about putting
/legacy/ in the title, because the API isn't legacy, the docs are. Maybe
we could use another path? Like /old-docs/ or something? I'd appreciate
some input on this.
2022-11-22 10:05:30 +01:00
Refer to [the documentation on role-based access control ](../reference/rbac.md ) for more information about the available roles and their permissions.
2021-02-25 16:01:36 +01:00
2022-06-17 12:36:19 +02:00
:::
2021-02-25 16:01:36 +01:00
2022-06-17 12:36:19 +02:00
## Required steps
2021-02-25 16:01:36 +01:00
2024-05-24 12:28:49 +02:00
This section takes you through the required steps to create and activate a feature flag. It assumes that you have all the prerequisites from the previous section done.
2021-02-25 16:01:36 +01:00
2024-05-24 12:28:49 +02:00
### Step 1: Create a flag {#step-1}
2021-02-25 16:01:36 +01:00
2024-05-24 12:28:49 +02:00
:::tip API: create a flag
2021-02-25 16:01:36 +01:00
2024-05-24 12:28:49 +02:00
Use the [Admin API endpoint for creating a feature flag ](/reference/api/legacy/unleash/admin/features-v2.md#create-toggle ). The payload accepts all the same fields as the Admin UI form. The Admin UI also displays the corresponding cURL command when you use the form.
2021-02-25 16:01:36 +01:00
2022-06-17 12:36:19 +02:00
:::
2021-02-25 16:01:36 +01:00
2024-05-24 12:28:49 +02:00
In the project that you want to create the flag in, use the "new feature flag" button and fill the form out with your desired configuration. Refer to the [feature flag reference documentation ](../reference/feature-toggles.mdx ) for the full list of configuration options and explanations.
2021-02-25 16:01:36 +01:00
2022-06-17 12:36:19 +02:00
![](/img/create-toggle-new-toggle.png)
### Step 2: Add a strategy {#step-2}
:::tip API: Add a strategy
2024-05-24 12:28:49 +02:00
Use the [API for adding a strategy to a feature flag ](/reference/api/legacy/unleash/admin/features-v2.md#add-strategy ). You can find the configuration options for each strategy in the [activation strategy reference documentation ](../reference/activation-strategies.md ).
2022-06-17 12:36:19 +02:00
:::
2024-05-24 12:28:49 +02:00
Decide which environment you want to enable the flag in. Select that environment and add an activation strategy. Different activation strategies will act differently as described in the [activation strategy documentation ](../reference/activation-strategies.md ). The configuration for each strategy differs accordingly. After selecting a strategy, complete the steps to configure it.
2022-06-17 12:36:19 +02:00
![](/img/create-toggle-add-strategy.png)
2024-05-24 12:28:49 +02:00
### Step 3: Enable the flag {#step-3}
2022-06-17 12:36:19 +02:00
2024-05-24 12:28:49 +02:00
:::tip API: Enable a flag
2022-06-17 12:36:19 +02:00
2024-05-24 12:28:49 +02:00
Use the [API for enabling an environment for a flag ](/reference/api/legacy/unleash/admin/features-v2.md#enable-env ) and specify the environment you'd like to enable.
2022-06-17 12:36:19 +02:00
:::
2024-05-24 12:28:49 +02:00
Use the environments flags to switch on the environment that you chose above. Depending on the activation strategy you added in the previous step, the flag should now evaluate to true or false depending on the Unleash context you provide it.
2022-06-17 12:36:19 +02:00
![](/img/create-toggle-enable-env.png)
## Optional steps
2024-05-24 12:28:49 +02:00
These optional steps allow you to further configure your feature flags to add optional payloads, variants for A/B testing, more detailed user targeting and exceptions/overrides.
2022-06-17 12:36:19 +02:00
### Add constraints and segmentation
refactor: move docs into new structure / fix links for SEO (#2416)
## What
This (admittedly massive) PR updates the "physical" documentation
structure and fixes url inconsistencies and SEO problems reported by
marketing. The main points are:
- remove or move directories : advanced, user_guide, deploy, api
- move the files contained within to the appropriate one of topics,
how-to, tutorials, or reference
- update internal doc links and product links to the content
- create client-side redirects for all the urls that have changed.
A number of the files have been renamed in small ways to better match
their url and to make them easier to find. Additionally, the top-level
api directory has been moved to /reference/api/legacy/unleash (see the
discussion points section for more on this).
## Why
When moving our doc structure to diataxis a while back, we left the
"physical' files lying where they were, because it didn't matter much to
the new structure. However, that did introduce some inconsistencies with
where you place docs and how we organize them.
There's also the discrepancies in whether urls us underscores or hyphens
(which isn't necessarily the same as their file name), which has been
annoying me for a while, but now has also been raised by marketing as an
issue in terms of SEO.
## Discussion points
The old, hand-written API docs have been moved from /api to
/reference/api/legacy/unleash. There _is_ a /reference/api/unleash
directory, but this is being populated by the OpenAPI plugin, and mixing
those could only cause trouble. However, I'm unsure about putting
/legacy/ in the title, because the API isn't legacy, the docs are. Maybe
we could use another path? Like /old-docs/ or something? I'd appreciate
some input on this.
2022-11-22 10:05:30 +01:00
Constraints and segmentation allow you to set filters on your strategies, so that they will only be evaluated for users and applications that match the specified preconditions. Refer to the [strategy constraints ](../reference/strategy-constraints.md 'strategy constraints reference documentation' ) and [segments reference documentation ](../reference/segments.mdx ) for more information.
2022-06-17 12:36:19 +02:00
To add constraints and segmentation, use the "edit strategy" button for the desired strategy.
![](/img/create-toggle-edit-strategy.png)
#### Constraints
:::info
2024-05-24 12:28:49 +02:00
Constraints aren't fixed and can be changed later to further narrow your audience. You can add them either when you add a strategy to a flag or at any point thereafter.
2022-06-17 12:36:19 +02:00
:::
:::tip API: Add constraints
refactor: move docs into new structure / fix links for SEO (#2416)
## What
This (admittedly massive) PR updates the "physical" documentation
structure and fixes url inconsistencies and SEO problems reported by
marketing. The main points are:
- remove or move directories : advanced, user_guide, deploy, api
- move the files contained within to the appropriate one of topics,
how-to, tutorials, or reference
- update internal doc links and product links to the content
- create client-side redirects for all the urls that have changed.
A number of the files have been renamed in small ways to better match
their url and to make them easier to find. Additionally, the top-level
api directory has been moved to /reference/api/legacy/unleash (see the
discussion points section for more on this).
## Why
When moving our doc structure to diataxis a while back, we left the
"physical' files lying where they were, because it didn't matter much to
the new structure. However, that did introduce some inconsistencies with
where you place docs and how we organize them.
There's also the discrepancies in whether urls us underscores or hyphens
(which isn't necessarily the same as their file name), which has been
annoying me for a while, but now has also been raised by marketing as an
issue in terms of SEO.
## Discussion points
The old, hand-written API docs have been moved from /api to
/reference/api/legacy/unleash. There _is_ a /reference/api/unleash
directory, but this is being populated by the OpenAPI plugin, and mixing
those could only cause trouble. However, I'm unsure about putting
/legacy/ in the title, because the API isn't legacy, the docs are. Maybe
we could use another path? Like /old-docs/ or something? I'd appreciate
some input on this.
2022-11-22 10:05:30 +01:00
You can either [add constraints when you add the strategy ](/reference/api/legacy/unleash/admin/features-v2.md#add-strategy ) or [PUT ](/reference/api/legacy/unleash/admin/features-v2.md#update-strategy 'PUT an activation strategy' ) or [PATCH the strategy afterwards ](/reference/api/legacy/unleash/admin/features-v2.md#put-strategy )
2022-06-17 12:36:19 +02:00
:::
2022-09-29 11:43:04 +02:00
In the strategy configuration screen for the strategy that you want to configure, use the "add constraint" button to add a strategy constraint.
2022-06-17 12:36:19 +02:00
![](/img/create-toggle-add-constraint.png)
#### Segments
:::info
This can be done after you have created a strategy.
:::
:::tip API: add segments
refactor: move docs into new structure / fix links for SEO (#2416)
## What
This (admittedly massive) PR updates the "physical" documentation
structure and fixes url inconsistencies and SEO problems reported by
marketing. The main points are:
- remove or move directories : advanced, user_guide, deploy, api
- move the files contained within to the appropriate one of topics,
how-to, tutorials, or reference
- update internal doc links and product links to the content
- create client-side redirects for all the urls that have changed.
A number of the files have been renamed in small ways to better match
their url and to make them easier to find. Additionally, the top-level
api directory has been moved to /reference/api/legacy/unleash (see the
discussion points section for more on this).
## Why
When moving our doc structure to diataxis a while back, we left the
"physical' files lying where they were, because it didn't matter much to
the new structure. However, that did introduce some inconsistencies with
where you place docs and how we organize them.
There's also the discrepancies in whether urls us underscores or hyphens
(which isn't necessarily the same as their file name), which has been
annoying me for a while, but now has also been raised by marketing as an
issue in terms of SEO.
## Discussion points
The old, hand-written API docs have been moved from /api to
/reference/api/legacy/unleash. There _is_ a /reference/api/unleash
directory, but this is being populated by the OpenAPI plugin, and mixing
those could only cause trouble. However, I'm unsure about putting
/legacy/ in the title, because the API isn't legacy, the docs are. Maybe
we could use another path? Like /old-docs/ or something? I'd appreciate
some input on this.
2022-11-22 10:05:30 +01:00
Use the [API for adding segments to a strategy ](/reference/api/legacy/unleash/admin/segments.mdx#replace-activation-strategy-segments ) to add segments to your strategy.
2022-06-17 12:36:19 +02:00
:::
In the strategy configuration screen for the strategy that you want to configure, use the "select segments" dropdown to add segments.
![](/img/create-toggle-add-segment.png)
### Add variants
2022-06-22 12:49:18 +02:00
2022-06-17 12:36:19 +02:00
:::info
2024-05-24 12:28:49 +02:00
This can be done at any point after you've created your flag.
2022-06-17 12:36:19 +02:00
:::
:::tip API: add variants
refactor: move docs into new structure / fix links for SEO (#2416)
## What
This (admittedly massive) PR updates the "physical" documentation
structure and fixes url inconsistencies and SEO problems reported by
marketing. The main points are:
- remove or move directories : advanced, user_guide, deploy, api
- move the files contained within to the appropriate one of topics,
how-to, tutorials, or reference
- update internal doc links and product links to the content
- create client-side redirects for all the urls that have changed.
A number of the files have been renamed in small ways to better match
their url and to make them easier to find. Additionally, the top-level
api directory has been moved to /reference/api/legacy/unleash (see the
discussion points section for more on this).
## Why
When moving our doc structure to diataxis a while back, we left the
"physical' files lying where they were, because it didn't matter much to
the new structure. However, that did introduce some inconsistencies with
where you place docs and how we organize them.
There's also the discrepancies in whether urls us underscores or hyphens
(which isn't necessarily the same as their file name), which has been
annoying me for a while, but now has also been raised by marketing as an
issue in terms of SEO.
## Discussion points
The old, hand-written API docs have been moved from /api to
/reference/api/legacy/unleash. There _is_ a /reference/api/unleash
directory, but this is being populated by the OpenAPI plugin, and mixing
those could only cause trouble. However, I'm unsure about putting
/legacy/ in the title, because the API isn't legacy, the docs are. Maybe
we could use another path? Like /old-docs/ or something? I'd appreciate
some input on this.
2022-11-22 10:05:30 +01:00
Use the [update variants endpoint ](/reference/api/legacy/unleash/admin/features-v2.md#update-variants ). The payload should be your desired variant configuration.
2022-06-17 12:36:19 +02:00
:::
2024-05-24 12:28:49 +02:00
[Variants ](../reference/feature-toggle-variants.md ) give you the ability to further target your users and split them into groups of your choosing, such as for A/B testing. On the flag overview page, select the variants tab. Use the "new variant" button to add the variants that you want.
2022-06-17 12:36:19 +02:00
![](/img/create-toggle-add-variants.png)
2023-02-27 12:49:53 +01:00
[^1]: Prior to Unleash 4.21, "create/edit variants" was a project-level permission instead of an environment-level permission.