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 integerID or URL-encoded path of the group
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20
order_by
Query
StringSort results by the specified field
Allowed values: id, username
Default: id
sort
Query
StringSort results in ascending or descending order
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 integerID or URL-encoded path of the group

Request body (application/json)

PropertyTypeDescription
emailStringEmail address of the user account. If omitted when creating a new service account, generates an email address prefixed with service_account_group_. Custom email addresses require confirmation, unless the group has a matching verified domain or email confirmation settings are turned off
nameStringName of the user. If omitted when creating a new service account, uses Service account user
usernameStringUsername of the user account. If omitted when creating a new service account, generates a username prefixed with service_account_group_

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 integerID or URL-encoded path of the group
user_id
Path, required
IntegerID 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 integerID or URL-encoded path of the group
user_id
Path, required
IntegerID of the service account

Request body (application/json)

PropertyTypeDescription
emailStringEmail address of the user account. If omitted when creating a new service account, generates an email address prefixed with service_account_group_. Custom email addresses require confirmation, unless the group has a matching verified domain or email confirmation settings are turned off
nameStringName of the user. If omitted when creating a new service account, uses Service account user
usernameStringUsername of the user account. If omitted when creating a new service account, generates a username prefixed with service_account_group_

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 integerID or URL-encoded path of the group
user_id
Path, required
IntegerID of the service account
hard_delete
Query
BooleanIf true, contributions that would usually be moved to a ghost user are deleted instead, along with groups owned solely by this service account

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 integerID or URL-encoded path of the group
revoked
Query
BooleanIf true, only returns revoked tokens. If false, only returns tokens that are not revoked
Example: false
state
Query
StringReturn tokens with the specified state
Allowed values: active, inactive
Example: active
created_before
Query
String (date-time)Return tokens created on or before the specified time
Example: 2022-01-01T00:00:00Z
created_after
Query
String (date-time)Return tokens created on or after the specified time
Example: 2021-01-01T00:00:00Z
last_used_before
Query
String (date-time)Return tokens last used on or before the specified time
Example: 2021-01-01T00:00:00Z
last_used_after
Query
String (date-time)Return tokens last used on or after the specified time
Example: 2022-01-01T00:00:00Z
expires_before
Query
String (date)Return tokens that expire before the specified date
Example: 2022-01-01
expires_after
Query
String (date)Return tokens that expire on or after the specified date
Example: 2021-01-01
search
Query
StringReturn tokens that include the specified value in their name
Example: token
sort
Query
StringSort results by the specified field and direction. Possible values are created_asc, created_desc, expires_asc, expires_desc, last_used_asc, last_used_desc, name_asc, and name_desc
Example: created_desc
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20
user_id
Path, required
IntegerID 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 integerID or URL-encoded path of the group
user_id
Path, required
IntegerID of the service account

Request body (application/json)

PropertyTypeDescription
descriptionStringDescription of the access token. Limited to 255 characters
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
StringName of the access token
Example: My token
scopes
Required
Array of stringsArray of approved scopes. For a list of possible values, see access token scopes

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 integerID or URL-encoded path of the group
token_id
Path, required
IntegerID of the personal access token
user_id
Path, required
IntegerID 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 integerID or URL-encoded path of the group
token_id
Path, required
IntegerID of the personal access token
user_id
Path, required
IntegerID of the service account

Request body (application/json)

PropertyTypeDescription
expires_atString (date)Date when the access token expires. Introduced in GitLab 17.9. If omitted, the new token expires one week after rotation when token expiry is enforced, and does not expire otherwise
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
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list 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
BooleanIf true, only returns revoked tokens. If false, only returns tokens that are not revoked
Example: false
state
Query
StringReturn tokens with the specified state
Allowed values: active, inactive
Example: active
created_before
Query
String (date-time)Return tokens created on or before the specified time
Example: 2022-01-01T00:00:00Z
created_after
Query
String (date-time)Return tokens created on or after the specified time
Example: 2021-01-01T00:00:00Z
last_used_before
Query
String (date-time)Return tokens last used on or before the specified time
Example: 2021-01-01T00:00:00Z
last_used_after
Query
String (date-time)Return tokens last used on or after the specified time
Example: 2022-01-01T00:00:00Z
expires_before
Query
String (date)Return tokens that expire before the specified date
Example: 2022-01-01
expires_after
Query
String (date)Return tokens that expire on or after the specified date
Example: 2021-01-01
search
Query
StringReturn tokens that include the specified value in their name
Example: token
sort
Query
StringSort results by the specified field and direction. Possible values are created_asc, created_desc, expires_asc, expires_desc, last_used_asc, last_used_desc, name_asc, and name_desc
Example: created_desc
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list 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
descriptionStringDescription of the access token. Limited to 255 characters
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
StringName 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
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list 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
externalBooleanFlag indicating the user is an external 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
externalBooleanFlag indicating the user is an external 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
externalBooleanExample: true
idInteger (int64)Example: 1
nameStringExample: Administrator
public_emailStringExample: john@example.com
unconfirmed_emailStringExample: updated_service_account@example.com
usernameStringExample: admin