Create a personal API token.
POST
/api/v1/tokens
const url = 'https://example.com/api/v1/tokens';const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"name":"github-actions","role":"developer","project":"shop","environment":"staging","expires_in_days":1}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://example.com/api/v1/tokens \ --header 'Content-Type: application/json' \ --data '{ "name": "github-actions", "role": "developer", "project": "shop", "environment": "staging", "expires_in_days": 1 }'Request Bodyrequired
Section titled “Request Bodyrequired”Media typeapplication/json
object
name
required
string
Example
github-actionsrole
Upper bound on what the token may do: viewer, developer or admin.
string
Example
developerproject
Restrict the token to one project.
string | null
Example
shopenvironment
Restrict the token to one environment of project.
string | null
Example
stagingexpires_in_days
Lifetime in days (1–365, default 90).
integer | null format: int32
Responses
Section titled “Responses”Media typeapplication/json
object
token
required
The token itself. Shown exactly once; only its hash is stored.
string
info
required
object
id
required
string
name
required
string
prefix
required
Non-secret prefix to recognise the token, e.g. kbn_pat_0192f3a1.
string
role
required
string
project
string | null
environment
string | null
expires_at
integer | null format: int64
last_used_at
integer | null format: int64
revoked
required
boolean
created_at
required
integer format: int64
Examplegenerated
{ "token": "example", "info": { "id": "example", "name": "example", "prefix": "example", "role": "example", "project": "example", "environment": "example", "expires_at": 1, "last_used_at": 1, "revoked": true, "created_at": 1 }}Media typeapplication/json
Problem Details body.
object
code
required
Stable machine-readable code, e.g. forbidden.
string
title
required
Short human readable title.
string
status
required
HTTP status.
integer format: int32
detail
Details, if safe to expose.
string | null
Example
{ "code": "forbidden"}Media typeapplication/json
Problem Details body.
object
code
required
Stable machine-readable code, e.g. forbidden.
string
title
required
Short human readable title.
string
status
required
HTTP status.
integer format: int32
detail
Details, if safe to expose.
string | null
Example
{ "code": "forbidden"}