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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
order_Query | String | Attribute to sort by Allowed values: id,usernameDefault: id |
sortQuery | String | Order of sorting Allowed values: asc,descDefault: desc |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | 400 Bad request | — |
401 | 401 Unauthorized | — |
403 | 403 Forbidden | — |
404 | 404 Group not found | — |
Create a group service account
POST /api/v4/groups/{id}/service_accounts
Creates a service account in a specified group.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
email | String | Custom email address for the user |
name | String | Name of the user |
username | String | Username of the user |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | 400 Bad request | — |
401 | 401 Unauthorized | — |
403 | 403 Forbidden | — |
404 | 404 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
user_Path, | Integer | The ID of the service account |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | 400 Bad request | — |
401 | 401 Unauthorized | — |
403 | 403 Forbidden | — |
404 | 404 User not found | — |
Update a group service account
PATCH /api/v4/groups/{id}/service_accounts/{user_id}
Update a specified group service account.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
user_Path, | Integer | The ID of the service account |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
email | String | Custom email address for the user |
name | String | Name of the user |
username | String | Username of the user |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | 400 Bad request | — |
401 | 401 Unauthorized | — |
403 | 403 Forbidden | — |
404 | 404 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
user_Path, | Integer | The ID of the service account |
hard_Query | Boolean | Whether to remove a user’s contributions |
Responses
| Code | Description | Schema |
|---|---|---|
204 | Resource deleted | — |
400 | 400 Bad request | — |
401 | 401 Unauthorized | — |
403 | 403 Forbidden | — |
404 | 404 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
revokedQuery | Boolean | Filter tokens where revoked state matches parameter Example: false |
stateQuery | String | Filter tokens which are either active or not Allowed values: active,inactiveExample: active |
created_Query | String (date- | Filter tokens which were created before given datetime Example: 2022- |
created_Query | String (date- | Filter tokens which were created after given datetime Example: 2021- |
last_Query | String (date- | Filter tokens which were used before given datetime Example: 2021- |
last_Query | String (date- | Filter tokens which were used after given datetime Example: 2022- |
expires_Query | String (date) | Filter tokens which expire before given datetime Example: 2022- |
expires_Query | String (date) | Filter tokens which expire after given datetime Example: 2021- |
searchQuery | String | Filters tokens by name Example: token |
sortQuery | String | Sort tokens Example: created_ |
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
user_Path, | Integer | The ID of the service account |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
401 | 401 Unauthorized | — |
403 | Forbidden | — |
404 | 404 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
user_Path, | Integer | The ID of the service account |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
description | String | The description of the access token Example: A token used for k8s |
expires_ | String (date) | Expiration date of the access token in ISO format (YYYY- Example: 2021- |
nameRequired | String | The name of the access token Example: My token |
scopesRequired | Array of strings | The array of scopes of the personal access token |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Bad Request | — |
404 | Not 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
token_Path, | Integer | The ID of the personal access token |
user_Path, | Integer | The ID of the service account |
Responses
| Code | Description | Schema |
|---|---|---|
204 | No Content | — |
400 | Bad Request | — |
401 | Unauthorized | — |
403 | Forbidden | — |
404 | Not 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
token_Path, | Integer | The ID of the personal access token |
user_Path, | Integer | The ID of the service account |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
expires_ | String (date) | The expiration date of the token Example: 2021- |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Bad Request | — |
404 | Not 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
order_Query | String | Attribute to sort by Allowed values: id,usernameDefault: id |
sortQuery | String | Order of sorting Allowed values: asc,descDefault: desc |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | 400 Bad request | — |
401 | 401 Unauthorized | — |
403 | 403 Forbidden | — |
404 | 404 Project not found | — |
Create a project service account
POST /api/v4/projects/{id}/service_accounts
Creates a service account in a specified project.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
email | String | Custom email address for the user |
name | String | Name of the user |
username | String | Username of the user |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | 400 Bad request | — |
401 | 401 Unauthorized | — |
403 | 403 Forbidden | — |
404 | 404 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
user_Path, | Integer | The ID of the service account |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | 400 Bad request | — |
401 | 401 Unauthorized | — |
403 | 403 Forbidden | — |
404 | 404 User not found | — |
Update a project service account
PATCH /api/v4/projects/{id}/service_accounts/{user_id}
Update a specified project service account.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
user_Path, | Integer | The ID of the service account |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
email | String | Custom email address for the user |
name | String | Name of the user |
username | String | Username of the user |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | 400 Bad request | — |
401 | 401 Unauthorized | — |
403 | 403 Forbidden | — |
404 | 404 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
user_Path, | Integer | The ID of the service account |
hard_Query | Boolean | Whether to remove a user’s contributions |
Responses
| Code | Description | Schema |
|---|---|---|
204 | No Content | — |
400 | 400 Bad request | — |
401 | 401 Unauthorized | — |
403 | 403 Forbidden | — |
404 | 404 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
revokedQuery | Boolean | Filter tokens where revoked state matches parameter Example: false |
stateQuery | String | Filter tokens which are either active or not Allowed values: active,inactiveExample: active |
created_Query | String (date- | Filter tokens which were created before given datetime Example: 2022- |
created_Query | String (date- | Filter tokens which were created after given datetime Example: 2021- |
last_Query | String (date- | Filter tokens which were used before given datetime Example: 2021- |
last_Query | String (date- | Filter tokens which were used after given datetime Example: 2022- |
expires_Query | String (date) | Filter tokens which expire before given datetime Example: 2022- |
expires_Query | String (date) | Filter tokens which expire after given datetime Example: 2021- |
searchQuery | String | Filters tokens by name Example: token |
sortQuery | String | Sort tokens Example: created_ |
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
user_Path, | Integer | The ID of the service account |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
401 | 401 Unauthorized | — |
403 | Forbidden | — |
404 | 404 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
user_Path, | Integer | The ID of the service account |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
description | String | The description of the access token Example: A token used for k8s |
expires_ | String (date) | Expiration date of the access token in ISO format (YYYY- Example: 2021- |
nameRequired | String | The name of the access token Example: My token |
scopesRequired | Array of strings | The array of scopes of the personal access token |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Bad Request | — |
404 | Not 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
token_Path, | Integer | The ID of the personal access token |
user_Path, | Integer | The ID of the service account |
Responses
| Code | Description | Schema |
|---|---|---|
204 | No Content | — |
400 | Bad Request | — |
401 | Unauthorized | — |
403 | Forbidden | — |
404 | Not 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
token_Path, | Integer | The ID of the personal access token |
user_Path, | Integer | The ID of the service account |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
expires_ | String (date) | The expiration date of the token Example: 2021- |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Bad Request | — |
404 | Not 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
| Name | Type | Description |
|---|---|---|
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
order_Query | String | Attribute to sort by Allowed values: id,usernameDefault: id |
sortQuery | String | Order of sorting Allowed values: asc,descDefault: desc |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | 400 Bad request | — |
401 | 401 Unauthorized | — |
403 | 403 Forbidden | — |
Create an instance service account
POST /api/v4/service_accounts
Creates an instance service account.
Request body (application/json)
| Property | Type | Description |
|---|---|---|
email | String | Custom email address for the user |
name | String | Name of the user |
username | String | Username of the user |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | 400 Bad request | — |
401 | 401 Unauthorized | — |
403 | 403 Forbidden | — |
Update an instance service account
PATCH /api/v4/service_accounts/{user_id}
Updates a specified instance service account.
Parameters
| Name | Type | Description |
|---|---|---|
user_Path, | Integer | The ID of the service account user |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
email | String | Custom email address for the user |
name | String | Name of the user |
username | String | Username of the user |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | 400 Bad request | — |
401 | 401 Unauthorized | — |
403 | 403 Forbidden | — |
404 | 404 Not found | — |
Schemas
Objects returned by the operations above and objects nested in their request bodies.
APIEntitiesPersonalAccessToken
| Property | Type | Description |
|---|---|---|
active | Boolean | — |
created_ | String (date- | — |
description | String | Example:Token to manage api |
expires_ | String (date- | Example:2020- |
granular | Boolean | — |
granular_ | Array of APIEntities | — |
id | Integer (int64) | Example:2 |
last_ | String (date- | Example:2020- |
last_ | Array of strings | The five most recent unique IP addresses that have authenticated with this token. Example: ["127. |
name | String | Example:John Doe |
revoked | Boolean | — |
scopes | Array | Example:["api"] |
user_ | Integer (int64) | Example:3 |
APIEntitiesPersonalAccessTokenGranularScope
| Property | Type | Description |
|---|---|---|
access | String | Example:personal_ |
group_ | Integer (int64) | Example:5 |
permissions | Array | Example:["read_ |
project_ | Integer (int64) | Example:3 |
APIEntitiesPersonalAccessTokenWithToken
| Property | Type | Description |
|---|---|---|
active | Boolean | — |
created_ | String (date- | — |
description | String | Example:Token to manage api |
expires_ | String (date- | Example:2020- |
granular | Boolean | — |
granular_ | Array of APIEntities | — |
id | Integer (int64) | Example:2 |
last_ | String (date- | Example:2020- |
last_ | Array of strings | The five most recent unique IP addresses that have authenticated with this token. Example: ["127. |
name | String | Example:John Doe |
revoked | Boolean | — |
scopes | Array | Example:["api"] |
token | String | — |
user_ | Integer (int64) | Example:3 |
APIEntitiesServiceAccount
| Property | Type | Description |
|---|---|---|
email | String | Example:service_ |
id | Integer (int64) | Example:1 |
name | String | Example:Administrator |
public_ | String | Example:john@example. |
unconfirmed_ | String | Example:updated_ |
username | String | Example:admin |