Create API token
Creates a new API token for the account with the given name and resource permissions. Unless expires_at is provided, the token expires 1 year after creation. Pass "expires_at": null to create a token that never expires. expires_at must be in the future and no more than 5 years ahead; past or unparseable values are rejected with a 422 error.
Pass the API token in the Api-Token
Display name for the token
When the token expires (ISO 8601 date-time, must be in the future). Must be no more than 5 years in the future. If omitted, the token expires 1 year after creation. Pass null to create a token that never expires. Past or unparseable values are rejected with a 422 error.
Created API token (includes full token value once)
API token ID
Token display name
Last 4 characters of the token (full token is only shown on create or reset)
Name of the user or token that created this token
When the token expires (ISO 8601); null if the token does not expire
Full token value (only returned on create or reset; store securely)
Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
Validation error or other business rule violation
curl -X POST https://mailtrap.io/api/api_tokens \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"name": "My API Token",
"expires_at": "2027-06-01T00:00:00Z",
"resources": [
{"resource_type": "account", "resource_id": 3229, "access_level": 100}
]
}'
{
"id": 12345,
"name": "My API Token",
"last_4_digits": "x7k9",
"created_by": "user@example.com",
"expires_at": null,
"resources": [
{
"resource_type": "account",
"resource_id": 3229,
"access_level": 100
}
],
"token": "a1b2c3d4e5f6..."
}Last updated
Was this helpful?

