For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

post
Authorizations
Api-TokenstringRequired

Pass the API token in the Api-Token

Body
namestring · max: 100Required

Display name for the token

expires_atstring · date-time · nullableOptional

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.

Responses
200

Created API token (includes full token value once)

application/json
idinteger · int64Optional

API token ID

namestringOptional

Token display name

last_4_digitsstringOptional

Last 4 characters of the token (full token is only shown on create or reset)

created_bystringOptional

Name of the user or token that created this token

expires_atstring · date-time · nullableOptional

When the token expires (ISO 8601); null if the token does not expire

tokenstringOptional

Full token value (only returned on create or reset; store securely)

post/api/api_tokens
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?