Create an API token.
Create a new personal access token or service account token in the workspace.
Unlike the other API token endpoints, this one requires no particular scope: any valid token can call it. What a token is allowed to create is bounded by its own type and its own scopes instead.
A token can only create another token of its own type: type must match the type of the token used to authenticate the call. A personal access token therefore creates personal access tokens owned by its own member, and a service account token creates service account tokens belonging to the workspace. There is no way to create a token on behalf of another member.
The requested scopes must be a subset of the scopes of the calling token.
A service account token whose creating user no longer exists cannot create tokens, and the call is rejected.
The response is the only place the new token's clear text key is exposed: it cannot be read again from the list or retrieve endpoints.
Creation is also rejected when the name is already used by an active token of the same type, when the workspace has reached its maximum number of active tokens, or when the requested lifetime exceeds the maximum lifetime allowed by the workspace policy.
Request body
Example request
{
"name": "myTokenName",
"type": "personal_access_token",
"scopes": [
"incidents:read",
"scan"
],
"lifetime": 30
}Response
API token created
Example response
{
"id": "5ddaad0c-5a0c-4674-beb5-1cd198d13360",
"name": "myTokenName",
"workspace_id": 42,
"type": "personal_access_token",
"status": "revoked",
"created_at": "2023-05-20T12:40:55.662949Z",
"last_used_at": "2023-05-24T12:40:55.662949Z",
"revoked_at": "2023-05-27T12:40:55.662949Z",
"member_id": 22015,
"creator_id": 22015,
"scopes": [
"incidents:read",
"scan"
],
"key": "gg_pat_AbCdEf123456..."
}