Use this API to interact with service accounts.

The number of service accounts you can create depends on your subscription and offering:

  • On GitLab Premium and Ultimate, you can create an unlimited number of service accounts for all offerings.
  • On GitLab Free, limits vary by offering:
    • For GitLab.com, you can create up to 100 service accounts for each top-level group. This includes service accounts created in subgroups or projects.
    • For GitLab Self-Managed, you can create up to 100 service accounts for the entire instance. This includes service accounts created for the instance, a group, or a project.

You can also interact with service accounts through the users API. To manage SSH keys for service accounts, use the user SSH and GPG keys API.

List all group service accounts

GET /api/v4/groups/{id}/service_accounts

Lists all service accounts in a specified group. Use the page and per_page pagination parameters to filter the results.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20
order_by
Query
StringAttribute to sort by
Allowed values: id, username
Default: id
sort
Query
StringOrder of sorting
Allowed values: asc, desc
Default: desc

Responses

CodeDescriptionSchema
200OKAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Group not found—

Create a group service account

POST /api/v4/groups/{id}/service_accounts

Creates a service account in a specified group.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group

Request body (application/json)

PropertyTypeDescription
emailStringCustom email address for the user
nameStringName of the user
usernameStringUsername of the user

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Group not found—

Get a single group service account

GET /api/v4/groups/{id}/service_accounts/{user_id}

Gets a specified service account in a specified group.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group
user_id
Path, required
IntegerThe ID of the service account

Responses

CodeDescriptionSchema
200OKAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 User not found—

Update a group service account

PATCH /api/v4/groups/{id}/service_accounts/{user_id}

Update a specified group service account.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group
user_id
Path, required
IntegerThe ID of the service account

Request body (application/json)

PropertyTypeDescription
emailStringCustom email address for the user
nameStringName of the user
usernameStringUsername of the user

Responses

CodeDescriptionSchema
200OKAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 User not found—

Delete a group service account

DELETE /api/v4/groups/{id}/service_accounts/{user_id}

Deletes a specified group service account. Available only for group Owners and administrators.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group
user_id
Path, required
IntegerThe ID of the service account
hard_delete
Query
BooleanWhether to remove a user’s contributions

Responses

CodeDescriptionSchema
204Resource deleted—
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Group not found—

List all personal access tokens for a group service account

GET /api/v4/groups/{id}/service_accounts/{user_id}/personal_access_tokens

Lists all personal access tokens for a specified group service account

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group
revoked
Query
BooleanFilter tokens where revoked state matches parameter
Example: false
state
Query
StringFilter tokens which are either active or not
Allowed values: active, inactive
Example: active
created_before
Query
String (date-time)Filter tokens which were created before given datetime
Example: 2022-01-01T00:00:00Z
created_after
Query
String (date-time)Filter tokens which were created after given datetime
Example: 2021-01-01T00:00:00Z
last_used_before
Query
String (date-time)Filter tokens which were used before given datetime
Example: 2021-01-01T00:00:00Z
last_used_after
Query
String (date-time)Filter tokens which were used after given datetime
Example: 2022-01-01T00:00:00Z
expires_before
Query
String (date)Filter tokens which expire before given datetime
Example: 2022-01-01
expires_after
Query
String (date)Filter tokens which expire after given datetime
Example: 2021-01-01
search
Query
StringFilters tokens by name
Example: token
sort
Query
StringSort tokens
Example: created_at_desc
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20
user_id
Path, required
IntegerThe ID of the service account

Responses

CodeDescriptionSchema
200OKAPIEntitiesPersonalAccessToken
400Bad Request—
401401 Unauthorized—
403Forbidden—
404404 Group Not Found—

Create a personal access token for a group service account

POST /api/v4/groups/{id}/service_accounts/{user_id}/personal_access_tokens

Creates a personal access token for a specified group service account. Available only for group Owners and administrators. This feature was introduced in GitLab 16.1.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group
user_id
Path, required
IntegerThe ID of the service account

Request body (application/json)

PropertyTypeDescription
descriptionStringThe description of the access token
Example: A token used for k8s
expires_atString (date)Expiration date of the access token in ISO format (YYYY-MM-DD). If undefined, the date is set to the maximum allowable lifetime limit
Example: 2021-01-31
name
Required
StringThe name of the access token
Example: My token
scopes
Required
Array of stringsThe array of scopes of the personal access token

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesPersonalAccessTokenWithToken
400Bad Request—
404Not Found—

Revoke a personal access token for a group service account

DELETE /api/v4/groups/{id}/service_accounts/{user_id}/personal_access_tokens/{token_id}

Revokes a specified personal access token for a group service account.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group
token_id
Path, required
IntegerThe ID of the personal access token
user_id
Path, required
IntegerThe ID of the service account

Responses

CodeDescriptionSchema
204No Content—
400Bad Request—
401Unauthorized—
403Forbidden—
404Not Found—

Rotate a personal access token for a group service account

POST /api/v4/groups/{id}/service_accounts/{user_id}/personal_access_tokens/{token_id}/rotate

Rotates a specified personal access token for a group service account. This revokes the existing token and creates a token with the same name, description, and scopes.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group
token_id
Path, required
IntegerThe ID of the personal access token
user_id
Path, required
IntegerThe ID of the service account

Request body (application/json)

PropertyTypeDescription
expires_atString (date)The expiration date of the token
Example: 2021-01-31

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesPersonalAccessTokenWithToken
400Bad Request—
404Not Found—

List all project service accounts

GET /api/v4/projects/{id}/service_accounts

Lists all service accounts in a specified project. Use the page and per_page pagination parameters to filter the results.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20
order_by
Query
StringAttribute to sort by
Allowed values: id, username
Default: id
sort
Query
StringOrder of sorting
Allowed values: asc, desc
Default: desc

Responses

CodeDescriptionSchema
200OKAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Project not found—

Create a project service account

POST /api/v4/projects/{id}/service_accounts

Creates a service account in a specified project.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project

Request body (application/json)

PropertyTypeDescription
emailStringCustom email address for the user
nameStringName of the user
usernameStringUsername of the user

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Project not found—

Get a single project service account

GET /api/v4/projects/{id}/service_accounts/{user_id}

Gets a specified service account in a specified project.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
user_id
Path, required
IntegerThe ID of the service account

Responses

CodeDescriptionSchema
200OKAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 User not found—

Update a project service account

PATCH /api/v4/projects/{id}/service_accounts/{user_id}

Update a specified project service account.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
user_id
Path, required
IntegerThe ID of the service account

Request body (application/json)

PropertyTypeDescription
emailStringCustom email address for the user
nameStringName of the user
usernameStringUsername of the user

Responses

CodeDescriptionSchema
200OKAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 User not found—

Delete a project service account

DELETE /api/v4/projects/{id}/service_accounts/{user_id}

Deletes a specified project service account. Available only for project Owners, Maintainers, and administrators.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
user_id
Path, required
IntegerThe ID of the service account
hard_delete
Query
BooleanWhether to remove a user’s contributions

Responses

CodeDescriptionSchema
204No Content—
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Project not found—

List all personal access tokens for a project service account

GET /api/v4/projects/{id}/service_accounts/{user_id}/personal_access_tokens

Lists all personal access tokens for a specified project service account

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
revoked
Query
BooleanFilter tokens where revoked state matches parameter
Example: false
state
Query
StringFilter tokens which are either active or not
Allowed values: active, inactive
Example: active
created_before
Query
String (date-time)Filter tokens which were created before given datetime
Example: 2022-01-01T00:00:00Z
created_after
Query
String (date-time)Filter tokens which were created after given datetime
Example: 2021-01-01T00:00:00Z
last_used_before
Query
String (date-time)Filter tokens which were used before given datetime
Example: 2021-01-01T00:00:00Z
last_used_after
Query
String (date-time)Filter tokens which were used after given datetime
Example: 2022-01-01T00:00:00Z
expires_before
Query
String (date)Filter tokens which expire before given datetime
Example: 2022-01-01
expires_after
Query
String (date)Filter tokens which expire after given datetime
Example: 2021-01-01
search
Query
StringFilters tokens by name
Example: token
sort
Query
StringSort tokens
Example: created_at_desc
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20
user_id
Path, required
IntegerThe ID of the service account

Responses

CodeDescriptionSchema
200OKAPIEntitiesPersonalAccessToken
400Bad Request—
401401 Unauthorized—
403Forbidden—
404404 Project Not Found—

Create a personal access token for a project service account

POST /api/v4/projects/{id}/service_accounts/{user_id}/personal_access_tokens

Creates a personal access token for a specified project service account. Available only for project Owners, Maintainers, and administrators.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
user_id
Path, required
IntegerThe ID of the service account

Request body (application/json)

PropertyTypeDescription
descriptionStringThe description of the access token
Example: A token used for k8s
expires_atString (date)Expiration date of the access token in ISO format (YYYY-MM-DD). If undefined, the date is set to the maximum allowable lifetime limit
Example: 2021-01-31
name
Required
StringThe name of the access token
Example: My token
scopes
Required
Array of stringsThe array of scopes of the personal access token

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesPersonalAccessTokenWithToken
400Bad Request—
404Not Found—

Revoke a personal access token for a project service account

DELETE /api/v4/projects/{id}/service_accounts/{user_id}/personal_access_tokens/{token_id}

Revokes a specified personal access token for a project service account.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
token_id
Path, required
IntegerThe ID of the personal access token
user_id
Path, required
IntegerThe ID of the service account

Responses

CodeDescriptionSchema
204No Content—
400Bad Request—
401Unauthorized—
403Forbidden—
404Not Found—

Rotate a personal access token for a project service account

POST /api/v4/projects/{id}/service_accounts/{user_id}/personal_access_tokens/{token_id}/rotate

Rotates a specified personal access token for a project service account. This revokes the existing token and creates a token with the same name, description, and scopes.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
token_id
Path, required
IntegerThe ID of the personal access token
user_id
Path, required
IntegerThe ID of the service account

Request body (application/json)

PropertyTypeDescription
expires_atString (date)The expiration date of the token
Example: 2021-01-31

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesPersonalAccessTokenWithToken
400Bad Request—
404Not Found—

List all instance service accounts

GET /api/v4/service_accounts

Lists all instance service accounts. Use the page and per_page pagination parameters to filter the results.

Parameters

NameTypeDescription
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20
order_by
Query
StringAttribute to sort by
Allowed values: id, username
Default: id
sort
Query
StringOrder of sorting
Allowed values: asc, desc
Default: desc

Responses

CodeDescriptionSchema
200OKAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—

Create an instance service account

POST /api/v4/service_accounts

Creates an instance service account.

Request body (application/json)

PropertyTypeDescription
emailStringCustom email address for the user
nameStringName of the user
usernameStringUsername of the user

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—

Update an instance service account

PATCH /api/v4/service_accounts/{user_id}

Updates a specified instance service account.

Parameters

NameTypeDescription
user_id
Path, required
IntegerThe ID of the service account user

Request body (application/json)

PropertyTypeDescription
emailStringCustom email address for the user
nameStringName of the user
usernameStringUsername of the user

Responses

CodeDescriptionSchema
200OKAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Not found—

Schemas

Objects returned by the operations above and objects nested in their request bodies.

APIEntitiesPersonalAccessToken

PropertyTypeDescription
activeBoolean—
created_atString (date-time)—
descriptionStringExample: Token to manage api
expires_atString (date-time)Example: 2020-08-31T15:53:00.073Z
granularBoolean—
granular_scopesArray of APIEntitiesPersonalAccessTokenGranularScope—
idInteger (int64)Example: 2
last_used_atString (date-time)Example: 2020-08-31T15:53:00.073Z
last_used_ipsArray of stringsThe five most recent unique IP addresses that have authenticated with this token. When the limit is reached, the oldest IP address is removed. The list updates once per minute per token
Example: ["127.0.0.1","127.0.0.2","127.0.0.3"]
nameStringExample: John Doe
revokedBoolean—
scopesArrayExample: ["api"]
user_idInteger (int64)Example: 3

APIEntitiesPersonalAccessTokenGranularScope

PropertyTypeDescription
accessStringExample: personal_projects
group_idInteger (int64)Example: 5
permissionsArrayExample: ["read_job"]
project_idInteger (int64)Example: 3

APIEntitiesPersonalAccessTokenWithToken

PropertyTypeDescription
activeBoolean—
created_atString (date-time)—
descriptionStringExample: Token to manage api
expires_atString (date-time)Example: 2020-08-31T15:53:00.073Z
granularBoolean—
granular_scopesArray of APIEntitiesPersonalAccessTokenGranularScope—
idInteger (int64)Example: 2
last_used_atString (date-time)Example: 2020-08-31T15:53:00.073Z
last_used_ipsArray of stringsThe five most recent unique IP addresses that have authenticated with this token. When the limit is reached, the oldest IP address is removed. The list updates once per minute per token
Example: ["127.0.0.1","127.0.0.2","127.0.0.3"]
nameStringExample: John Doe
revokedBoolean—
scopesArrayExample: ["api"]
tokenString—
user_idInteger (int64)Example: 3

APIEntitiesServiceAccount

PropertyTypeDescription
emailStringExample: service_account@example.com
idInteger (int64)Example: 1
nameStringExample: Administrator
public_emailStringExample: john@example.com
unconfirmed_emailStringExample: updated_service_account@example.com
usernameStringExample: admin