2021-01-29 16:09:34 -05:00
---
stage: Manage
group: Access
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
---
# Project access tokens API
You can read more about [project access tokens ](../user/project/settings/project_access_tokens.md ).
## List project access tokens
2021-06-15 08:10:11 -04:00
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/238991) in GitLab 13.9.
2021-01-29 16:09:34 -05:00
Get a list of project access tokens.
```plaintext
2021-02-03 16:09:17 -05:00
GET projects/:id/access_tokens
2021-01-29 16:09:34 -05:00
```
| Attribute | Type | required | Description |
|-----------|---------|----------|---------------------|
2021-06-28 11:08:03 -04:00
| `id` | integer or string | yes | The ID or [URL-encoded path of the project ](index.md#namespaced-path-encoding ) |
2021-01-29 16:09:34 -05:00
```shell
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/< project_id > /access_tokens"
```
```json
[
{
"user_id" : 141,
"scopes" : [
"api"
],
"name" : "token",
"expires_at" : "2021-01-31",
"id" : 42,
"active" : true,
"created_at" : "2021-01-20T22:11:48.151Z",
2021-06-24 08:08:07 -04:00
"revoked" : false,
"access_level": 40
2021-01-29 16:09:34 -05:00
}
]
```
## Create a project access token
2021-06-15 08:10:11 -04:00
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55408) in GitLab 13.10.
2021-01-29 16:09:34 -05:00
Create a project access token.
```plaintext
2021-02-03 16:09:17 -05:00
POST projects/:id/access_tokens
2021-01-29 16:09:34 -05:00
```
| Attribute | Type | required | Description |
|-----------|---------|----------|---------------------|
2021-06-28 11:08:03 -04:00
| `id` | integer or string | yes | The ID or [URL-encoded path of the project ](index.md#namespaced-path-encoding ) |
2021-01-29 16:09:34 -05:00
| `name` | String | yes | The name of the project access token |
2021-06-14 23:10:34 -04:00
| `scopes` | `Array[String]` | yes | [List of scopes ](../user/project/settings/project_access_tokens.md#limiting-scopes-of-a-project-access-token ) |
2021-06-29 08:08:48 -04:00
| `access_level` | Integer | no | A valid access level. Default value is 40 (Maintainer). Other allowed values are 10 (Guest), 20 (Reporter), and 30 (Developer). |
2021-01-29 16:09:34 -05:00
| `expires_at` | Date | no | The token expires at midnight UTC on that date |
```shell
curl --request POST --header "PRIVATE-TOKEN: < your_access_token > " \
--header "Content-Type:application/json" \
2021-06-29 08:08:48 -04:00
--data '{ "name":"test_token", "scopes":["api", "read_repository"], "expires_at":"2021-01-31", "access_level": 30 }' \
2021-01-29 16:09:34 -05:00
"https://gitlab.example.com/api/v4/projects/< project_id > /access_tokens"
```
```json
{
"scopes" : [
"api",
"read_repository"
],
"active" : true,
"name" : "test",
"revoked" : false,
"created_at" : "2021-01-21T19:35:37.921Z",
"user_id" : 166,
"id" : 58,
2021-03-02 10:10:57 -05:00
"expires_at" : "2021-01-31",
2021-06-24 08:08:07 -04:00
"token" : "D4y...Wzr",
2021-06-29 08:08:48 -04:00
"access_level": 30
2021-01-29 16:09:34 -05:00
}
```
## Revoke a project access token
2021-06-15 08:10:11 -04:00
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/238991) in GitLab 13.9.
2021-01-29 16:09:34 -05:00
Revoke a project access token.
```plaintext
2021-02-03 16:09:17 -05:00
DELETE projects/:id/access_tokens/:token_id
2021-01-29 16:09:34 -05:00
```
| Attribute | Type | required | Description |
|-----------|---------|----------|---------------------|
2021-06-28 11:08:03 -04:00
| `id` | integer or string | yes | The ID or [URL-encoded path of the project ](index.md#namespaced-path-encoding ) |
2021-06-14 23:10:34 -04:00
| `token_id` | integer or string | yes | The ID of the project access token |
2021-01-29 16:09:34 -05:00
```shell
curl --request DELETE --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/< project_id > /access_tokens/< token_id > "
```
### Responses
- `204: No Content` if successfully revoked.
- `400 Bad Request` or `404 Not Found` if not revoked successfully.