2020-06-23 00:09:42 +05:30
---
2023-06-20 00:43:36 +05:30
stage: Deploy
group: Environments
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2020-06-23 00:09:42 +05:30
---
2022-11-25 23:54:43 +05:30
# Feature flags API **(FREE)**
2019-12-26 22:10:19 +05:30
2021-04-29 21:17:54 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/9566) in GitLab Premium 12.5.
> - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/212318) to GitLab Free in 13.5.
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
API for accessing resources of [GitLab feature flags ](../operations/feature_flags.md ).
2019-12-26 22:10:19 +05:30
2023-07-09 08:55:56 +05:30
Users with at least the Developer [role ](../user/permissions.md ) can access the feature flag API.
2019-12-26 22:10:19 +05:30
2022-11-25 23:54:43 +05:30
## Feature flags pagination
2019-12-26 22:10:19 +05:30
By default, `GET` requests return 20 results at a time because the API results
2023-04-23 21:23:45 +05:30
are [paginated ](rest/index.md#pagination ).
2019-12-26 22:10:19 +05:30
## List feature flags for a project
Gets all feature flags of the requested project.
2020-04-08 14:13:33 +05:30
```plaintext
2019-12-26 22:10:19 +05:30
GET /projects/:id/feature_flags
```
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------- |
2023-04-23 21:23:45 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](rest/index.md#namespaced-path-encoding ). |
2019-12-26 22:10:19 +05:30
| `scope` | string | no | The condition of feature flags, one of: `enabled` , `disabled` . |
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/feature_flags"
2019-12-26 22:10:19 +05:30
```
Example response:
```json
[
{
"name":"merge_train",
"description":"This feature is about merge train",
2020-10-24 23:57:45 +05:30
"active": true,
2020-06-23 00:09:42 +05:30
"version": "new_version_flag",
2019-12-26 22:10:19 +05:30
"created_at":"2019-11-04T08:13:51.423Z",
"updated_at":"2019-11-04T08:13:51.423Z",
2020-06-23 00:09:42 +05:30
"scopes":[],
"strategies": [
{
"id": 1,
"name": "userWithId",
"parameters": {
"userIds": "user1"
},
"scopes": [
{
"id": 1,
"environment_scope": "production"
}
]
}
2019-12-26 22:10:19 +05:30
]
},
{
"name":"new_live_trace",
"description":"This is a new live trace feature",
2020-10-24 23:57:45 +05:30
"active": true,
2020-06-23 00:09:42 +05:30
"version": "new_version_flag",
2019-12-26 22:10:19 +05:30
"created_at":"2019-11-04T08:13:10.507Z",
"updated_at":"2019-11-04T08:13:10.507Z",
2021-06-08 01:23:25 +05:30
"scopes":[],
2020-06-23 00:09:42 +05:30
"strategies": [
{
"id": 2,
"name": "default",
"parameters": {},
"scopes": [
{
"id": 2,
"environment_scope": "staging"
}
]
}
2019-12-26 22:10:19 +05:30
]
}
]
```
2020-06-23 00:09:42 +05:30
## Get a single feature flag
Gets a single feature flag.
```plaintext
2020-10-24 23:57:45 +05:30
GET /projects/:id/feature_flags/:feature_flag_name
2020-06-23 00:09:42 +05:30
```
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
2023-04-23 21:23:45 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](rest/index.md#namespaced-path-encoding ). |
2020-10-24 23:57:45 +05:30
| `feature_flag_name` | string | yes | The name of the feature flag. |
2020-06-23 00:09:42 +05:30
```shell
2021-02-22 17:27:13 +05:30
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"
2020-06-23 00:09:42 +05:30
```
Example response:
```json
{
"name": "awesome_feature",
"description": null,
2020-10-24 23:57:45 +05:30
"active": true,
2020-06-23 00:09:42 +05:30
"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-12-26 22:10:19 +05:30
Creates a new feature flag.
2020-04-08 14:13:33 +05:30
```plaintext
2019-12-26 22:10:19 +05:30
POST /projects/:id/feature_flags
```
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
2023-04-23 21:23:45 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](rest/index.md#namespaced-path-encoding ). |
2020-06-23 00:09:42 +05:30
| `name` | string | yes | The name of the feature flag. |
2023-01-13 00:05:48 +05:30
| `version` | string | yes | The version of the feature flag. Must be `new_version_flag` . Omit to create a Legacy feature flag. |
2020-06-23 00:09:42 +05:30
| `description` | string | no | The description of the feature flag. |
2020-10-24 23:57:45 +05:30
| `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-28 23:09:34 +05:30
| `strategies` | JSON | no | The feature flag [strategies ](../operations/feature_flags.md#feature-flag-strategies ). |
2023-04-23 21:23:45 +05:30
| `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://docs.getunleash.io/user_guide/activation_strategy/#gradual-rollout ). |
2020-06-23 00:09:42 +05:30
| `strategies:parameters` | JSON | no | The strategy parameters. |
| `strategies:scopes` | JSON | no | The scopes for the strategy. |
2023-01-13 00:05:48 +05:30
| `strategies:scopes:environment_scope` | string | no | The environment scope of the scope. |
2019-12-26 22:10:19 +05:30
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl "https://gitlab.example.com/api/v4/projects/1/feature_flags" \
2019-12-26 22:10:19 +05:30
--header "PRIVATE-TOKEN: < your_access_token > " \
--header "Content-type: application/json" \
--data @- < < EOF
{
2020-06-23 00:09:42 +05:30
"name": "awesome_feature",
"version": "new_version_flag",
"strategies": [{ "name": "default", "parameters": {}, "scopes": [{ "environment_scope": "production" }] }]
2019-12-26 22:10:19 +05:30
}
EOF
```
Example response:
```json
{
2020-06-23 00:09:42 +05:30
"name": "awesome_feature",
"description": null,
2020-10-24 23:57:45 +05:30
"active": true,
2020-06-23 00:09:42 +05:30
"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-12-26 22:10:19 +05:30
}
```
2020-06-23 00:09:42 +05:30
## Update a feature flag
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
Updates a feature flag.
2019-12-26 22:10:19 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2020-10-24 23:57:45 +05:30
PUT /projects/:id/feature_flags/:feature_flag_name
2019-12-26 22:10:19 +05:30
```
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
2023-04-23 21:23:45 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](rest/index.md#namespaced-path-encoding ). |
2020-10-24 23:57:45 +05:30
| `feature_flag_name` | string | yes | The current name of the feature flag. |
2020-06-23 00:09:42 +05:30
| `description` | string | no | The description of the feature flag. |
2020-10-24 23:57:45 +05:30
| `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. |
| `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-28 23:09:34 +05:30
| `strategies` | JSON | no | The feature flag [strategies ](../operations/feature_flags.md#feature-flag-strategies ). |
2020-11-24 15:15:51 +05:30
| `strategies:id` | JSON | no | The feature flag strategy ID. |
2020-06-23 00:09:42 +05:30
| `strategies:name` | JSON | no | The strategy name. |
2023-03-17 16:20:25 +05:30
| `strategies:_destroy` | boolean | no | Delete the strategy when true. |
2020-06-23 00:09:42 +05:30
| `strategies:parameters` | JSON | no | The strategy parameters. |
| `strategies:scopes` | JSON | no | The scopes for the strategy. |
2023-01-13 00:05:48 +05:30
| `strategies:scopes:id` | JSON | no | The environment scope ID. |
| `strategies:scopes:environment_scope` | string | no | The environment scope of the scope. |
2023-03-17 16:20:25 +05:30
| `strategies:scopes:_destroy` | boolean | no | Delete the scope when true. |
2019-12-26 22:10:19 +05:30
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature" \
--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-12-26 22:10:19 +05:30
```
Example response:
```json
{
2020-06-23 00:09:42 +05:30
"name": "awesome_feature",
"description": null,
2020-10-24 23:57:45 +05:30
"active": true,
2020-06-23 00:09:42 +05:30
"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-12-26 22:10:19 +05:30
},
2020-06-23 00:09:42 +05:30
"scopes": [
{
"id": 40,
"environment_scope": "staging"
}
]
},
{
"id": 37,
"name": "default",
"parameters": {},
"scopes": [
{
"id": 39,
"environment_scope": "production"
}
]
}
]
2019-12-26 22:10:19 +05:30
}
```
2020-06-23 00:09:42 +05:30
## Delete a feature flag
2019-12-26 22:10:19 +05:30
Deletes a feature flag.
2020-04-08 14:13:33 +05:30
```plaintext
2020-10-24 23:57:45 +05:30
DELETE /projects/:id/feature_flags/:feature_flag_name
2019-12-26 22:10:19 +05:30
```
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
2023-04-23 21:23:45 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](rest/index.md#namespaced-path-encoding ). |
2020-10-24 23:57:45 +05:30
| `feature_flag_name` | string | yes | The name of the feature flag. |
2019-12-26 22:10:19 +05:30
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --header "PRIVATE-TOKEN: < your_access_token > " --request DELETE "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"
2019-12-26 22:10:19 +05:30
```