2020-06-17 03:08:38 +00:00
---
stage: Release
2020-12-01 15:09:28 +00:00
group: Release
2020-11-26 06:09:20 +00:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-06-17 03:08:38 +00:00
---
2020-10-13 15:08:53 +00:00
# Feature Flags API **(CORE)**
2019-11-14 18:06:15 +00:00
2020-10-13 15:08:53 +00:00
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/9566) in [GitLab Premium](https://about.gitlab.com/pricing/) 12.5.
> - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/212318) to [GitLab Starter](https://about.gitlab.com/pricing/) in 13.4.
> - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/212318) to [GitLab Core](https://about.gitlab.com/pricing/) in 13.5.
2019-11-14 18:06:15 +00:00
2020-07-09 21:09:33 +00:00
API for accessing resources of [GitLab Feature Flags ](../operations/feature_flags.md ).
2019-11-14 18:06:15 +00:00
Users with Developer or higher [permissions ](../user/permissions.md ) can access Feature Flag API.
## Feature Flags pagination
By default, `GET` requests return 20 results at a time because the API results
are [paginated ](README.md#pagination ).
## List feature flags for a project
Gets all feature flags of the requested project.
2020-02-28 00:09:08 +00:00
```plaintext
2019-11-14 18:06:15 +00:00
GET /projects/:id/feature_flags
```
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ). |
| `scope` | string | no | The condition of feature flags, one of: `enabled` , `disabled` . |
2020-01-30 15:09:15 +00:00
```shell
2020-05-28 00:08:37 +00:00
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/feature_flags"
2019-11-14 18:06:15 +00:00
```
Example response:
```json
[
{
"name":"merge_train",
"description":"This feature is about merge train",
2020-08-03 09:09:42 +00:00
"active": true,
2020-05-22 15:08:09 +00:00
"version": "new_version_flag",
2019-11-14 18:06:15 +00:00
"created_at":"2019-11-04T08:13:51.423Z",
"updated_at":"2019-11-04T08:13:51.423Z",
2020-05-22 15:08:09 +00:00
"scopes":[],
"strategies": [
{
"id": 1,
"name": "userWithId",
"parameters": {
"userIds": "user1"
},
"scopes": [
{
"id": 1,
"environment_scope": "production"
}
]
}
2019-11-14 18:06:15 +00:00
]
},
{
"name":"new_live_trace",
"description":"This is a new live trace feature",
2020-08-03 09:09:42 +00:00
"active": true,
2020-05-22 15:08:09 +00:00
"version": "new_version_flag",
2019-11-14 18:06:15 +00:00
"created_at":"2019-11-04T08:13:10.507Z",
"updated_at":"2019-11-04T08:13:10.507Z",
2020-05-22 15:08:09 +00:00
"scopes":[]
"strategies": [
{
"id": 2,
"name": "default",
"parameters": {},
"scopes": [
{
"id": 2,
"environment_scope": "staging"
}
]
}
2019-11-14 18:06:15 +00:00
]
}
]
```
2020-05-22 15:08:09 +00:00
## Get a single feature flag
Gets a single feature flag.
```plaintext
2020-08-05 12:09:45 +00:00
GET /projects/:id/feature_flags/:feature_flag_name
2020-05-22 15:08:09 +00:00
```
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ). |
2020-08-05 12:09:45 +00:00
| `feature_flag_name` | string | yes | The name of the feature flag. |
2020-05-22 15:08:09 +00:00
```shell
2020-12-08 09:09:41 +00:00
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"
2020-05-22 15:08:09 +00:00
```
Example response:
```json
{
"name": "awesome_feature",
"description": null,
2020-08-03 09:09:42 +00:00
"active": true,
2020-05-22 15:08:09 +00:00
"version": "new_version_flag",
"created_at": "2020-05-13T19:56:33.119Z",
"updated_at": "2020-05-13T19:56:33.119Z",
"scopes": [],
"strategies": [
{
"id": 36,
"name": "default",
"parameters": {},
"scopes": [
{
"id": 37,
"environment_scope": "production"
}
]
}
]
}
```
## Create a feature flag
2019-11-14 18:06:15 +00:00
Creates a new feature flag.
2020-02-28 00:09:08 +00:00
```plaintext
2019-11-14 18:06:15 +00:00
POST /projects/:id/feature_flags
```
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ). |
2020-05-22 15:08:09 +00:00
| `name` | string | yes | The name of the feature flag. |
| `version` | string | yes | The version of the feature flag. Must be `new_version_flag` . Omit or set to `legacy_flag` to create a [Legacy Feature Flag ](feature_flags_legacy.md ). |
| `description` | string | no | The description of the feature flag. |
2020-08-03 09:09:42 +00:00
| `active` | boolean | no | The active state of the flag. Defaults to true. [Supported ](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38350 ) in GitLab 13.3 and later. |
2020-07-09 21:09:33 +00:00
| `strategies` | JSON | no | The feature flag [strategies ](../operations/feature_flags.md#feature-flag-strategies ). |
2020-10-02 00:08:51 +00:00
| `strategies:name` | JSON | no | The strategy name. Can be `default` , `gradualRolloutUserId` , `userWithId` , or `gitlabUserList` . In [GitLab 13.5 ](https://gitlab.com/gitlab-org/gitlab/-/issues/36380 ) and later, can be [`flexibleRollout` ](https://unleash.github.io/docs/activation_strategy#flexiblerollout ). |
2020-05-22 15:08:09 +00:00
| `strategies:parameters` | JSON | no | The strategy parameters. |
| `strategies:scopes` | JSON | no | The scopes for the strategy. |
| `strategies:scopes:environment_scope` | string | no | The environment spec for the scope. |
2019-11-14 18:06:15 +00:00
2020-01-30 15:09:15 +00:00
```shell
2020-05-28 00:08:37 +00:00
curl "https://gitlab.example.com/api/v4/projects/1/feature_flags" \
2019-11-14 18:06:15 +00:00
--header "PRIVATE-TOKEN: < your_access_token > " \
--header "Content-type: application/json" \
--data @- < < EOF
{
2020-05-22 15:08:09 +00:00
"name": "awesome_feature",
"version": "new_version_flag",
"strategies": [{ "name": "default", "parameters": {}, "scopes": [{ "environment_scope": "production" }] }]
2019-11-14 18:06:15 +00:00
}
EOF
```
Example response:
```json
{
2020-05-22 15:08:09 +00:00
"name": "awesome_feature",
"description": null,
2020-08-03 09:09:42 +00:00
"active": true,
2020-05-22 15:08:09 +00:00
"version": "new_version_flag",
"created_at": "2020-05-13T19:56:33.119Z",
"updated_at": "2020-05-13T19:56:33.119Z",
"scopes": [],
"strategies": [
{
"id": 36,
"name": "default",
"parameters": {},
"scopes": [
{
"id": 37,
"environment_scope": "production"
}
]
}
]
2019-11-14 18:06:15 +00:00
}
```
2020-05-22 15:08:09 +00:00
## Update a feature flag
2019-11-14 18:06:15 +00:00
2020-05-22 15:08:09 +00:00
Updates a feature flag.
2019-11-14 18:06:15 +00:00
2020-02-28 00:09:08 +00:00
```plaintext
2020-08-05 12:09:45 +00:00
PUT /projects/:id/feature_flags/:feature_flag_name
2019-11-14 18:06:15 +00:00
```
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ). |
2020-08-05 12:09:45 +00:00
| `feature_flag_name` | string | yes | The current name of the feature flag. |
2020-05-22 15:08:09 +00:00
| `description` | string | no | The description of the feature flag. |
2020-08-03 09:09:42 +00:00
| `active` | boolean | no | The active state of the flag. [Supported ](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38350 ) in GitLab 13.3 and later. |
2020-08-05 12:09:45 +00:00
| `name` | string | no | The new name of the feature flag. [Supported ](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38350 ) in GitLab 13.3 and later. |
2020-07-09 21:09:33 +00:00
| `strategies` | JSON | no | The feature flag [strategies ](../operations/feature_flags.md#feature-flag-strategies ). |
2020-08-21 00:10:44 +00:00
| `strategies:id` | JSON | no | The feature flag strategy ID. |
2020-05-22 15:08:09 +00:00
| `strategies:name` | JSON | no | The strategy name. |
| `strategies:parameters` | JSON | no | The strategy parameters. |
| `strategies:scopes` | JSON | no | The scopes for the strategy. |
2020-08-21 00:10:44 +00:00
| `strategies:scopes:id` | JSON | no | The scopes ID. |
2020-05-22 15:08:09 +00:00
| `strategies:scopes:environment_scope` | string | no | The environment spec for the scope. |
2019-11-14 18:06:15 +00:00
2020-01-30 15:09:15 +00:00
```shell
2020-05-28 00:08:37 +00:00
curl "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature" \
2020-05-22 15:08:09 +00:00
--header "PRIVATE-TOKEN: < your_access_token > " \
--header "Content-type: application/json" \
--data @- < < EOF
{
"strategies": [{ "name": "gradualRolloutUserId", "parameters": { "groupId": "default", "percentage": "25" }, "scopes": [{ "environment_scope": "staging" }] }]
}
EOF
2019-11-14 18:06:15 +00:00
```
Example response:
```json
{
2020-05-22 15:08:09 +00:00
"name": "awesome_feature",
"description": null,
2020-08-03 09:09:42 +00:00
"active": true,
2020-05-22 15:08:09 +00:00
"version": "new_version_flag",
"created_at": "2020-05-13T20:10:32.891Z",
"updated_at": "2020-05-13T20:10:32.891Z",
"scopes": [],
"strategies": [
{
"id": 38,
"name": "gradualRolloutUserId",
"parameters": {
"groupId": "default",
"percentage": "25"
2019-11-14 18:06:15 +00:00
},
2020-05-22 15:08:09 +00:00
"scopes": [
{
"id": 40,
"environment_scope": "staging"
}
]
},
{
"id": 37,
"name": "default",
"parameters": {},
"scopes": [
{
"id": 39,
"environment_scope": "production"
}
]
}
]
2019-11-14 18:06:15 +00:00
}
```
2020-05-22 15:08:09 +00:00
## Delete a feature flag
2019-11-14 18:06:15 +00:00
Deletes a feature flag.
2020-02-28 00:09:08 +00:00
```plaintext
2020-08-05 12:09:45 +00:00
DELETE /projects/:id/feature_flags/:feature_flag_name
2019-11-14 18:06:15 +00:00
```
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ). |
2020-08-05 12:09:45 +00:00
| `feature_flag_name` | string | yes | The name of the feature flag. |
2019-11-14 18:06:15 +00:00
2020-01-30 15:09:15 +00:00
```shell
2020-05-28 00:08:37 +00:00
curl --header "PRIVATE-TOKEN: < your_access_token > " --request DELETE "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"
2019-11-14 18:06:15 +00:00
```