Personal Access Tokens#



List personal access tokens:

access_tokens = gl.personal_access_tokens.list()

List personal access tokens from other user_id (admin only):

access_tokens = gl.personal_access_tokens.list(user_id=25)

Revoke a personal access token fetched via list:

access_token = access_tokens[0]

Revoke a personal access token by id:


Revoke the personal access token currently used:


Create a personal access token for a user (admin only):

user = gl.users.get(25, lazy=True)
access_token = user.personal_access_tokens.create({"name": "test", "scopes": "api"})


As you can see above, you can only create personal access tokens via the Users API, but you cannot revoke these objects directly. This is because the create API uses a different endpoint than the list and revoke APIs. You need to fetch the token via the list API first to revoke it.

As of 14.2, GitLab does not provide a GET API for single personal access tokens. You must use the list method to retrieve single tokens.