Help us learn about your current experience with the documentation. Take the survey.

Feature flag API

  • Tier: Free, Premium, Ultimate
  • Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated

Use this API to interact with GitLab feature flags.

Prerequisites:

  • You must have the Developer, Maintainer, or Owner role.

List feature flags for a project

Gets all feature flags of the requested project.

GET /projects/:id/feature_flags

Use the page and per_page pagination parameters to control the pagination of results.

AttributeTypeRequiredDescription
idinteger or stringyesThe ID or URL-encoded path of the project.
scopestringnoThe condition of feature flags, one of: enabled, disabled.
curl --request GET \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/feature_flags"

Example response:

[
   {
      "name":"merge_train",
      "description":"This feature is about merge train",
      "active": true,
      "version": "new_version_flag",
      "created_at":"2019-11-04T08:13:51.423Z",
      "updated_at":"2019-11-04T08:13:51.423Z",
      "scopes":[],
      "strategies": [
        {
          "id": 1,
          "name": "userWithId",
          "parameters": {
            "userIds": "user1"
          },
          "scopes": [
            {
              "id": 1,
              "environment_scope": "production"
            }
          ],
          "user_list": null
        }
      ]
   },
   {
      "name":"new_live_trace",
      "description":"This is a new live trace feature",
      "active": true,
      "version": "new_version_flag",
      "created_at":"2019-11-04T08:13:10.507Z",
      "updated_at":"2019-11-04T08:13:10.507Z",
      "scopes":[],
      "strategies": [
        {
          "id": 2,
          "name": "default",
          "parameters": {},
          "scopes": [
            {
              "id": 2,
              "environment_scope": "staging"
            }
          ],
          "user_list": null
        }
      ]
   },
   {
      "name":"user_list",
      "description":"This feature is about user list",
      "active": true,
      "version": "new_version_flag",
      "created_at":"2019-11-04T08:13:10.507Z",
      "updated_at":"2019-11-04T08:13:10.507Z",
      "scopes":[],
      "strategies": [
        {
          "id": 2,
          "name": "gitlabUserList",
          "parameters": {},
          "scopes": [
            {
              "id": 2,
              "environment_scope": "staging"
            }
          ],
          "user_list": {
            "id": 1,
            "iid": 1,
            "name": "My user list",
            "user_xids": "user1,user2,user3"
          }
        }
      ]
   }
]

Retrieve a feature flag

Retrieves a specified feature flag.

GET /projects/:id/feature_flags/:feature_flag_name

Use the page and per_page pagination parameters to control the pagination of results.

AttributeTypeRequiredDescription
idinteger or stringyesThe ID or URL-encoded path of the project.
feature_flag_namestringyesThe name of the feature flag.
curl --request GET \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"

Example response:

{
  "name": "awesome_feature",
  "description": null,
  "active": true,
  "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"
        }
      ],
      "user_list": null
    }
  ]
}

Create a feature flag

Creates a feature flag for a specified project.

POST /projects/:id/feature_flags
AttributeTypeRequiredDescription
idinteger or stringyesThe ID or URL-encoded path of the project.
namestringyesThe name of the feature flag.
versionstringyesDeprecated The version of the feature flag. Must be new_version_flag. Omit to create a Legacy feature flag.
descriptionstringnoThe description of the feature flag.
activebooleannoThe active state of the flag. Defaults to true.
strategiesarray of strategy JSON objectsnoThe feature flag strategies.
strategies:nameJSONnoThe strategy name. Can be default, gradualRolloutUserId, userWithId, gitlabUserList, or flexibleRollout.
strategies:parametersJSONnoThe strategy parameters.
strategies:scopesJSONnoThe scopes for the strategy.
strategies:scopes:environment_scopestringnoThe environment scope of the scope.
strategies:user_list_idinteger or stringnoThe ID of the feature flag user list. If strategy is gitlabUserList.
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --header "Content-type: application/json" \
  --data @- \
  --url "https://gitlab.example.com/api/v4/projects/1/feature_flags" << EOF
{
  "name": "awesome_feature",
  "version": "new_version_flag",
  "strategies": [{ "name": "default", "parameters": {}, "scopes": [{ "environment_scope": "production" }] }]
}
EOF

Example response:

{
  "name": "awesome_feature",
  "description": null,
  "active": true,
  "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"
        }
      ]
    }
  ]
}

Update a feature flag

Updates a specified feature flag.

PUT /projects/:id/feature_flags/:feature_flag_name
AttributeTypeRequiredDescription
idinteger or stringyesThe ID or URL-encoded path of the project.
feature_flag_namestringyesThe current name of the feature flag.
descriptionstringnoThe description of the feature flag.
activebooleannoThe active state of the flag.
namestringnoThe new name of the feature flag.
strategiesarray of strategy JSON objectsnoThe feature flag strategies.
strategies:idJSONnoThe feature flag strategy ID.
strategies:nameJSONnoThe strategy name.
strategies:_destroybooleannoDelete the strategy when true.
strategies:parametersJSONnoThe strategy parameters.
strategies:scopesJSONnoThe scopes for the strategy.
strategies:scopes:idJSONnoThe environment scope ID.
strategies:scopes:environment_scopestringnoThe environment scope of the scope.
strategies:scopes:_destroybooleannoDelete the scope when true.
strategies:user_list_idinteger or stringnoThe ID of the feature flag user list. If strategy is gitlabUserList.
curl --request PUT \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --header "Content-type: application/json" \
  --data @- \
  --url "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature" << EOF
{
  "strategies": [{ "name": "gradualRolloutUserId", "parameters": { "groupId": "default", "percentage": "25" }, "scopes": [{ "environment_scope": "staging" }] }]
}
EOF

Example response:

{
  "name": "awesome_feature",
  "description": null,
  "active": true,
  "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"
      },
      "scopes": [
        {
          "id": 40,
          "environment_scope": "staging"
        }
      ]
    },
    {
      "id": 37,
      "name": "default",
      "parameters": {},
      "scopes": [
        {
          "id": 39,
          "environment_scope": "production"
        }
      ]
    }
  ]
}

Delete a feature flag

Deletes a specified feature flag.

DELETE /projects/:id/feature_flags/:feature_flag_name
AttributeTypeRequiredDescription
idinteger or stringyesThe ID or URL-encoded path of the project.
feature_flag_namestringyesThe name of the feature flag.
curl --request DELETE \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"

Retrieve feature flag settings

The feature flag controls enforcement of minimum_role, but not access to this endpoint. For more information, see the history.

Retrieves the feature flag settings of a specified project.

GET /projects/:id/feature_flags_settings
AttributeTypeRequiredDescription
idinteger or stringyesThe ID or URL-encoded path of the project.
curl --request GET \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/feature_flags_settings"

Example response:

{
   "minimum_role": "developer"
}

Update feature flag settings

The feature flag controls enforcement of minimum_role, but not access to this endpoint. For more information, see the history.

Updates the feature flag settings of a specified project.

Prerequisites:

  • You must have at least the Maintainer role for the project.
  • To change minimum_role away from owner or no_one_allowed, you must have the Owner role for the project.
PUT /projects/:id/feature_flags_settings
AttributeTypeRequiredDescription
idinteger or stringyesThe ID or URL-encoded path of the project.
minimum_rolestringyesMinimum role required to manage feature flags. One of no_one_allowed, developer, maintainer, or owner.
curl --request PUT \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/feature_flags_settings?minimum_role=maintainer"

Example response:

{
   "minimum_role": "maintainer"
}

For what each value means, see restrict who can manage feature flags.