Use this API to interact with access tokens including:
List all group access tokens
GET /api/v4/groups/{id}/access_tokens
Lists all group access tokens for a specified group.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
revokedQuery | Boolean | If true,false,Example: false |
stateQuery | String | Return tokens with the specified state Allowed values: all,active,inactiveExample: active |
created_Query | String (date- | Return tokens created on or before the specified time Example: 2022- |
created_Query | String (date- | Return tokens created on or after the specified time Example: 2021- |
last_Query | String (date- | Return tokens last used on or before the specified time Example: 2021- |
last_Query | String (date- | Return tokens last used on or after the specified time Example: 2022- |
expires_Query | String (date) | Return tokens that expire before the specified date Example: 2022- |
expires_Query | String (date) | Return tokens that expire on or after the specified date Example: 2021- |
searchQuery | String | Return tokens that include the specified value in their name Example: token |
sortQuery | String | Sort results by the specified field and direction.created_,created_,expires_,expires_,last_,last_,name_,name_Example: created_ |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Create a group access token
POST /api/v4/groups/{id}/access_tokens
Creates a group access token for a specified group. You cannot create a token with an access level greater than your account. For example, a user with the Maintainer role cannot create a group access token with the Owner role. You must use a personal access token with this endpoint. You cannot authenticate with a group access token.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- Example: 2 |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
access_ | Integer | The access level of the token in the group Allowed values: 10,15,20,25,30,40,50Default: 40 |
description | String | Description of the access token. Example: A token used for k8s |
expires_ | String (date) | Date when the access token expires. Example: 2026- |
nameRequired | String | Name of the access token Example: My token |
scopesRequired | Array of strings | List of scopes available to the token |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Rotate a group access token
POST /api/v4/groups/{id}/access_tokens/self/rotate
Rotates a group access token by passing it to the API in a header.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
expires_ | String (date) | Date when the access token expires. Example: 2021- |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
401 | Unauthorized | — |
403 | Forbidden | — |
404 | Not Found | — |
405 | Method not allowed | — |
Retrieve details on a group access token
GET /api/v4/groups/{id}/access_tokens/{token_id}
Retrieves details on a specified group access token.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
token_Path, | String | ID of the token |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Revoke a group access token
DELETE /api/v4/groups/{id}/access_tokens/{token_id}
Revokes a specified group access token.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- |
token_Path, | String | ID of the token |
Responses
| Code | Description | Schema |
|---|---|---|
204 | No Content | — |
400 | Bad Request | — |
404 | Not found | — |
Rotate a group access token
POST /api/v4/groups/{id}/access_tokens/{token_id}/rotate
Rotates a group access token. This immediately revokes the previous token and creates a token. Generally, this endpoint rotates a specific group access token by authenticating with a personal access token. You can also use a group access token to rotate itself. If you attempt to use this endpoint to rotate a token that was previously revoked, any active tokens from the same token family are revoked. This feature was introduced in GitLab 16.0.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- |
token_Path, | String | ID of the token |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
expires_ | String (date) | Date when the access token expires. Example: 2021- |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | 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. For tokens created with granular scopes, the response also includes a granular_scopes attribute. The last_used_ips attribute was introduced in GitLab 19.4. The granular_scopes attribute was introduced in GitLab 19.6. This feature was introduced in GitLab 17.11.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
revokedQuery | Boolean | If true,false,Example: false |
stateQuery | String | Return tokens with the specified state Allowed values: all,active,inactiveExample: active |
created_Query | String (date- | Return tokens created on or before the specified time Example: 2022- |
created_Query | String (date- | Return tokens created on or after the specified time Example: 2021- |
last_Query | String (date- | Return tokens last used on or before the specified time Example: 2021- |
last_Query | String (date- | Return tokens last used on or after the specified time Example: 2022- |
expires_Query | String (date) | Return tokens that expire before the specified date Example: 2022- |
expires_Query | String (date) | Return tokens that expire on or after the specified date Example: 2021- |
searchQuery | String | Return tokens that include the specified value in their name Example: token |
sortQuery | String | Sort results by the specified field and direction.created_,created_,expires_,expires_,last_,last_,name_,name_Example: created_ |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
user_Path, | Integer | ID of the service account |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of 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. The last_used_ips attribute was introduced in GitLab 19.4. This feature was introduced in GitLab 16.1.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
user_Path, | Integer | ID of the service account |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
description | String | 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 | Name of the access token Example: My token |
scopesRequired | Array of strings | Array of approved scopes. |
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. This feature was introduced in GitLab 17.11.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
token_Path, | Integer | ID of the personal access token |
user_Path, | Integer | 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. Rotating a token with granular scopes returns those scopes in a granular_scopes attribute on the new token. The last_used_ips attribute was introduced in GitLab 19.4. The granular_scopes attribute was introduced in GitLab 19.5.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
token_Path, | Integer | ID of the personal access token |
user_Path, | Integer | ID of the service account |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
expires_ | String (date) | Date when the access token expires. Example: 2021- |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
List all personal access tokens
GET /api/v4/personal_access_tokens
Lists all personal access tokens accessible by the authenticated user. For administrators, returns all personal access tokens in the instance. For non-administrators, returns all of their personal access tokens.
Parameters
| Name | Type | Description |
|---|---|---|
user_Query | Integer | Filter personal access tokens by user ID. Example: 2 |
revokedQuery | Boolean | If true,false,Example: false |
stateQuery | String | Return tokens with the specified state Allowed values: all,active,inactiveExample: active |
created_Query | String (date- | Return tokens created on or before the specified time Example: 2022- |
created_Query | String (date- | Return tokens created on or after the specified time Example: 2021- |
last_Query | String (date- | Return tokens last used on or before the specified time Example: 2021- |
last_Query | String (date- | Return tokens last used on or after the specified time Example: 2022- |
expires_Query | String (date) | Return tokens that expire before the specified date Example: 2022- |
expires_Query | String (date) | Return tokens that expire on or after the specified date Example: 2021- |
searchQuery | String | Return tokens that include the specified value in their name Example: token |
sortQuery | String | Sort results by the specified field and direction.created_,created_,expires_,expires_,last_,last_,name_,name_Example: created_ |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of APIEntities |
400 | Bad Request | — |
401 | Unauthorized | — |
Retrieve a personal access token
GET /api/v4/personal_access_tokens/self
Retrieves a specified personal access token by passing it to the API in a header.
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
401 | Unauthorized | — |
404 | Not found | — |
Revoke a personal access token
DELETE /api/v4/personal_access_tokens/self
Revokes a personal access token by passing it to the API in a header.
Responses
| Code | Description | Schema |
|---|---|---|
204 | No Content | — |
400 | Bad Request | — |
List all token associations
GET /api/v4/personal_access_tokens/self/associations
Lists all groups and projects accessible by the personal access token used to authenticate the request. Generally, this includes any groups or projects that the user is a member of.
Parameters
| Name | Type | Description |
|---|---|---|
min_Query | Integer | Return groups and projects where the current user has at least the specified access level. Allowed values: 10,15,20,25,30,40,50 |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
401 | Unauthorized | — |
404 | Not found | — |
Rotate a personal access token
POST /api/v4/personal_access_tokens/self/rotate
Rotates a personal access token by passing it to the API in a header
Request body (application/json)
| Property | Type | Description |
|---|---|---|
expires_ | String (date) | Date when the access token expires. Example: 2021- |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
401 | Unauthorized | — |
403 | Forbidden | — |
405 | Method not allowed | — |
Retrieve a personal access token
GET /api/v4/personal_access_tokens/{id}
Retrieves details for a specified personal access token. Administrators can retrieve details on any token. Non-administrators can only retrieve details on their own tokens.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | Integer | ID of the personal access token |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
401 | Unauthorized | — |
404 | Not found | — |
Revoke a personal access token
DELETE /api/v4/personal_access_tokens/{id}
Revokes a specified personal access token. Administrators can revoke tokens for any user. Non-administrators can only revoke their own tokens.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | Integer | ID of the personal access token |
Responses
| Code | Description | Schema |
|---|---|---|
204 | No Content | — |
400 | Bad Request | — |
404 | Not Found | — |
Rotate a personal access token
POST /api/v4/personal_access_tokens/{id}/rotate
Rotates a specified personal access token. This revokes the previous token and creates a token that expires after one week. Administrators can revoke tokens for any user. Non-administrators can only revoke their own tokens.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | Integer | ID of the personal access token |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
expires_ | String (date) | Date when the access token expires. Example: 2021- |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
List all project access tokens
GET /api/v4/projects/{id}/access_tokens
Lists all project access tokens for a specified project.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
revokedQuery | Boolean | If true,false,Example: false |
stateQuery | String | Return tokens with the specified state Allowed values: all,active,inactiveExample: active |
created_Query | String (date- | Return tokens created on or before the specified time Example: 2022- |
created_Query | String (date- | Return tokens created on or after the specified time Example: 2021- |
last_Query | String (date- | Return tokens last used on or before the specified time Example: 2021- |
last_Query | String (date- | Return tokens last used on or after the specified time Example: 2022- |
expires_Query | String (date) | Return tokens that expire before the specified date Example: 2022- |
expires_Query | String (date) | Return tokens that expire on or after the specified date Example: 2021- |
searchQuery | String | Return tokens that include the specified value in their name Example: token |
sortQuery | String | Sort results by the specified field and direction.created_,created_,expires_,expires_,last_,last_,name_,name_Example: created_ |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Create a project access token
POST /api/v4/projects/{id}/access_tokens
Creates a project access token for a specified project. You cannot create a token with an access level greater than your account. For example, a user with the Maintainer role cannot create a project access token with the Owner role. You must use a personal access token with this endpoint. You cannot authenticate with a project access token.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- Example: 2 |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
access_ | Integer | The access level of the token in the project Allowed values: 10,15,20,25,30,40,50Default: 40 |
description | String | Description of the access token. Example: A token used for k8s |
expires_ | String (date) | Date when the access token expires. Example: 2026- |
nameRequired | String | Name of the access token Example: My token |
scopesRequired | Array of strings | List of scopes available to the token |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Rotate a project access token
POST /api/v4/projects/{id}/access_tokens/self/rotate
Rotates a project access token by passing it to the API in a header.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
expires_ | String (date) | Date when the access token expires. Example: 2021- |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
401 | Unauthorized | — |
403 | Forbidden | — |
404 | Not Found | — |
405 | Method not allowed | — |
Retrieve details on a project access token
GET /api/v4/projects/{id}/access_tokens/{token_id}
Retrieves details on a specified project access token.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
token_Path, | String | ID of the token |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Revoke a project access token
DELETE /api/v4/projects/{id}/access_tokens/{token_id}
Revokes a specified project access token.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- |
token_Path, | String | ID of the token |
Responses
| Code | Description | Schema |
|---|---|---|
204 | No Content | — |
400 | Bad Request | — |
404 | Not found | — |
Rotate a project access token
POST /api/v4/projects/{id}/access_tokens/{token_id}/rotate
Rotates a project access token. This immediately revokes the previous token and creates a token. Generally, this endpoint rotates a specific project access token by authenticating with a personal access token. You can also use a project access token to rotate itself. If you attempt to use this endpoint to rotate a token that was previously revoked, any active tokens from the same token family are revoked. This feature was introduced in GitLab 16.0.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- |
token_Path, | String | ID of the token |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
expires_ | String (date) | Date when the access token expires. Example: 2021- |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | 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. For tokens created with granular scopes, the response also includes a granular_scopes attribute. The last_used_ips attribute was introduced in GitLab 19.4. The granular_scopes attribute was introduced in GitLab 19.6.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
revokedQuery | Boolean | If true,false,Example: false |
stateQuery | String | Return tokens with the specified state Allowed values: all,active,inactiveExample: active |
created_Query | String (date- | Return tokens created on or before the specified time Example: 2022- |
created_Query | String (date- | Return tokens created on or after the specified time Example: 2021- |
last_Query | String (date- | Return tokens last used on or before the specified time Example: 2021- |
last_Query | String (date- | Return tokens last used on or after the specified time Example: 2022- |
expires_Query | String (date) | Return tokens that expire before the specified date Example: 2022- |
expires_Query | String (date) | Return tokens that expire on or after the specified date Example: 2021- |
searchQuery | String | Return tokens that include the specified value in their name Example: token |
sortQuery | String | Sort results by the specified field and direction.created_,created_,expires_,expires_,last_,last_,name_,name_Example: created_ |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
user_Path, | Integer | ID of the service account |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of 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. The last_used_ips attribute was introduced in GitLab 19.4.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
user_Path, | Integer | ID of the service account |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
description | String | 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 | Name of the access token Example: My token |
scopesRequired | Array of strings | Array of approved scopes. |
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 | ID or URL- |
token_Path, | Integer | ID of the personal access token |
user_Path, | Integer | 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. Rotating a token with granular scopes returns those scopes in a granular_scopes attribute on the new token. The last_used_ips attribute was introduced in GitLab 19.4. The granular_scopes attribute was introduced in GitLab 19.5.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
token_Path, | Integer | ID of the personal access token |
user_Path, | Integer | ID of the service account |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
expires_ | String (date) | Date when the access token expires. Example: 2021- |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Create a personal access token
POST /api/v4/user/personal_access_tokens
Creates a personal access token for the currently authenticated user. To create a fine-grained personal access token, use granular_scopes instead of scopes. For security purposes, a token created with scopes is limited to the k8s_proxy and self_rotate scope. With selected_memberships, you must have access to each group and project listed. Token values are included with the response, but cannot be retrieved later. The granular_scopes parameter was introduced in GitLab 19.2. The last_used_ips attribute was introduced in GitLab 19.4. The granular_scopes attribute in the response was introduced in GitLab 19.5.
Request body (application/json)
| Property | Type | Description |
|---|---|---|
description | String | 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- |
granular_ | Array of objects | List of granular scopes to assign.scopes,granular_ must be provided |
granular_Required | String | Access to configure for the granular scope Allowed values: personal_,all_,selected_,user,instanceMinimum length: 1 |
granular_ | Array of integers | IDs of groups to associate with the granular scope,selected_ |
granular_Required | Array of strings | List of permissions for the granular scope |
granular_ | Array of integers | IDs of projects to associate with the granular scope,selected_ |
nameRequired | String | Name of the access token Example: My token |
scopes | Array of strings | Array of approved scopes.scopes,granular_ must be provided |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Bad Request | — |
List all impersonation tokens for a user
GET /api/v4/users/{user_id}/impersonation_tokens
Lists all impersonation tokens for a specified user. Administrators only. The last_used_ips attribute was introduced in GitLab 19.2 and made generally available in GitLab 19.4. The granular_scopes attribute was introduced in GitLab 19.5.
Parameters
| Name | Type | Description |
|---|---|---|
user_Path, | Integer | ID of the user |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
revokedQuery | Boolean | If true,false,Example: false |
stateQuery | String | Return tokens with the specified state Allowed values: all,active,inactiveExample: active |
created_Query | String (date- | Return tokens created on or before the specified time Example: 2022- |
created_Query | String (date- | Return tokens created on or after the specified time Example: 2021- |
last_Query | String (date- | Return tokens last used on or before the specified time Example: 2021- |
last_Query | String (date- | Return tokens last used on or after the specified time Example: 2022- |
expires_Query | String (date) | Return tokens that expire before the specified date Example: 2022- |
expires_Query | String (date) | Return tokens that expire on or after the specified date Example: 2021- |
searchQuery | String | Return tokens that include the specified value in their name Example: token |
sortQuery | String | Sort results by the specified field and direction.created_,created_,expires_,expires_,last_,last_,name_,name_Example: created_ |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Create an impersonation token
POST /api/v4/users/{user_id}/impersonation_tokens
Creates an impersonation token for a specified user. These tokens are used to act on behalf of a user and can perform API calls as well as Git read and write actions. These tokens are not visible to the associated user on their profile settings page. To create a fine-grained impersonation token, use granular_scopes instead of scopes. The scopes in granular_scopes apply to the user the token is for. With selected_memberships, that user must have access to each group and project listed. Either scopes or granular_scopes is required. Token values are included with the response, but cannot be retrieved later. Administrators only. The last_used_ips attribute was introduced in GitLab 19.2 and made generally available in GitLab 19.4. The granular_scopes parameter was introduced in GitLab 19.2, and the granular_scopes attribute in the response was introduced in GitLab 19.5.
Parameters
| Name | Type | Description |
|---|---|---|
user_Path, | Integer | ID of the user |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
description | String | Description of the impersonation token. |
expires_ | String (date) | Date when the impersonation token expires. |
granular_ | Array of objects | List of granular scopes to assign.scopes |
granular_Required | String | Access to configure for the granular scope Allowed values: personal_,all_,selected_,user,instanceMinimum length: 1 |
granular_ | Array of integers | IDs of groups to associate with the granular scope,selected_ |
granular_Required | Array of strings | List of permissions for the granular scope |
granular_ | Array of integers | IDs of projects to associate with the granular scope,selected_ |
nameRequired | String | Name of the impersonation token |
scopes | Array of strings | Array of approved scopes.granular_ is not provided.granular_ |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Retrieve an impersonation token for a user
GET /api/v4/users/{user_id}/impersonation_tokens/{impersonation_token_id}
Retrieves an impersonation token for a specified user. Administrators only. The last_used_ips attribute was introduced in GitLab 19.2 and made generally available in GitLab 19.4. The granular_scopes attribute was introduced in GitLab 19.5.
Parameters
| Name | Type | Description |
|---|---|---|
user_Path, | Integer | ID of the user |
impersonation_Path, | Integer | ID of the impersonation token |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Revoke an impersonation token
DELETE /api/v4/users/{user_id}/impersonation_tokens/{impersonation_token_id}
Revokes an impersonation token for a specified user. Administrators only.
Parameters
| Name | Type | Description |
|---|---|---|
user_Path, | Integer | ID of the user |
impersonation_Path, | Integer | ID of the impersonation token |
Responses
| Code | Description | Schema |
|---|---|---|
204 | No Content | — |
400 | Bad Request | — |
404 | Not Found | — |
Create a personal access token for a user
POST /api/v4/users/{user_id}/personal_access_tokens
Creates a personal access token for a user. To create a fine-grained personal access token, use granular_scopes instead of scopes. The scopes in granular_scopes apply to the user the token is for. With selected_memberships, that user must have access to each group and project listed. Token values are included with the response, but cannot be retrieved later. Administrators only. The last_used_ips attribute was introduced in GitLab 19.4. The granular_scopes attribute was introduced in GitLab 19.6.
Parameters
| Name | Type | Description |
|---|---|---|
user_Path, | Integer | ID of the user |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
description | String | 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- |
granular_ | Array of objects | List of granular scopes to assign.scopes,granular_ must be provided |
granular_Required | String | Access to configure for the granular scope Allowed values: personal_,all_,selected_,user,instanceMinimum length: 1 |
granular_ | Array of integers | IDs of groups to associate with the granular scope,selected_ |
granular_Required | Array of strings | List of permissions for the granular scope |
granular_ | Array of integers | IDs of projects to associate with the granular scope,selected_ |
nameRequired | String | Name of the access token Example: My token |
scopes | Array of strings | Array of approved scopes.scopes,granular_ must be provided |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Schemas
Objects returned by the operations above and objects nested in their request bodies.
APIEntitiesGranularScope
| Property | Type | Description |
|---|---|---|
access | String | Example:personal_ |
group_ | Integer (int64) | Example:5 |
permissions | Array | Example:["read_ |
project_ | Integer (int64) | Example:3 |
APIEntitiesImpersonationToken
| 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 |
impersonation | Boolean | Example:true |
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 |
APIEntitiesImpersonationTokenWithToken
| 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 |
impersonation | Boolean | Example:true |
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 | Example:glpat- |
user_ | Integer (int64) | Example:3 |
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 |
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 | Example:glpat- |
user_ | Integer (int64) | Example:3 |
APIEntitiesResourceAccessToken
| Property | Type | Description |
|---|---|---|
access_ | Integer | Allowed values:10,20,30,40,50Example: 40 |
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 |
resource_ | Integer | Example:1234 |
resource_ | String | Allowed values:project,groupExample: project |
revoked | Boolean | — |
scopes | Array | Example:["api"] |
user_ | Integer (int64) | Example:3 |
APIEntitiesResourceAccessTokenWithToken
| Property | Type | Description |
|---|---|---|
access_ | Integer | Allowed values:10,20,30,40,50Example: 40 |
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 |
resource_ | Integer | Example:1234 |
resource_ | String | Allowed values:project,groupExample: project |
revoked | Boolean | — |
scopes | Array | Example:["api"] |
token | String | Example:glpat- |
user_ | Integer (int64) | Example:3 |