gitlab-org--gitlab-foss/doc/api/project_access_tokens.md

4.7 KiB

stage group info
Manage Authentication and Authorization 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 (FREE)

You can read more about project access tokens.

List project access tokens

Introduced in GitLab 13.9.

Get a list of project access tokens.

GET projects/:id/access_tokens
Attribute Type required Description
id integer or string yes ID or URL-encoded path of the project
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/<project_id>/access_tokens"
[
   {
      "user_id" : 141,
      "scopes" : [
         "api"
      ],
      "name" : "token",
      "expires_at" : "2021-01-31",
      "id" : 42,
      "active" : true,
      "created_at" : "2021-01-20T22:11:48.151Z",
      "revoked" : false,
      "access_level": 40
   }
]

Get a project access token

Introduced in GitLab 14.10.

Get a project access token by ID.

GET projects/:id/access_tokens/:token_id
Attribute Type required Description
id integer or string yes ID or URL-encoded path of the project
token_id integer or string yes ID of the project access token
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/<project_id>/access_tokens/<token_id>"
{
   "user_id" : 141,
   "scopes" : [
      "api"
   ],
   "name" : "token",
   "expires_at" : "2021-01-31",
   "id" : 42,
   "active" : true,
   "created_at" : "2021-01-20T22:11:48.151Z",
   "revoked" : false,
   "access_level": 40,
   "last_used_at": "2022-03-15T11:05:42.437Z"
}

Create a project access token

Create a project access token.

POST projects/:id/access_tokens
Attribute Type required Description
id integer or string yes ID or URL-encoded path of the project
name String yes Name of the project access token
scopes Array[String] yes List of scopes
access_level Integer no A valid access level. Default value is 40 (Maintainer). Other allowed values are 10 (Guest), 20 (Reporter), and 30 (Developer).
expires_at Date no Token expires at midnight UTC on that date
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type:application/json" \
--data '{ "name":"test_token", "scopes":["api", "read_repository"], "expires_at":"2021-01-31", "access_level": 30 }' \
"https://gitlab.example.com/api/v4/projects/<project_id>/access_tokens"
{
   "scopes" : [
      "api",
      "read_repository"
   ],
   "active" : true,
   "name" : "test",
   "revoked" : false,
   "created_at" : "2021-01-21T19:35:37.921Z",
   "user_id" : 166,
   "id" : 58,
   "expires_at" : "2021-01-31",
   "token" : "D4y...Wzr",
   "access_level": 30
}

Revoke a project access token

Introduced in GitLab 13.9.

Revoke a project access token.

DELETE projects/:id/access_tokens/:token_id
Attribute Type required Description
id integer or string yes ID or URL-encoded path of the project
token_id integer or string yes ID of the project access token
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.