# POST /tokens

First published 3 Oct 2026 (release 0.1.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the auth group.

Create an API token for the caller

- Who may call it: administrator, reseller, customer
- Token scope, any of: all
- Answers: 201 Created

This operation requires the all scope. Supply scopes as an array or a comma-separated string. The default is read. Accepted scopes are read, domains, dns, certificates, mail, databases, files, users, backups, settings, security, export, license, and all. An empty scope list or an unknown scope returns 400.

The read scope covers every GET request except export downloads. The export scope covers export and import. The all scope can also be written as * and covers every scope except export. A login session with all therefore cannot grant export. Use urbestack-token-create at the shell to create a token with export. The API returns 403 if the calling token cannot grant one or more requested scopes.

The label defaults to api and accepts up to 64 characters. Set expires_in to a lifetime in whole seconds. The default is 0, which gives the token an unlimited lifetime. Set address to bind the token to a client IPv4 or IPv6 address. UrbeStack rejects and revokes the token if it is presented from a different IP address.

The 201 response contains the token secret, which is shown only once.

## As a command

- [urbestack-token-create](https://urbestack.com/docs/commands/urbestack-token-create.md): Creates a token for the active UrbeStack user named by --user.

## Request body

JSON, the type [TokenCreate](https://urbestack.com/docs/api/types/TokenCreate.md).

- `address` (string, up to 45 characters): Client IP address to bind the token to. A request from a different IP address is refused and revokes the token. Omit this field to allow requests from any IP address. A session token is always bound to the client IP address used at login.
- `expires_in` (integer, 0 to 315360000): Number of seconds until the token expires. Use 0 or omit the field for a token that never expires.
- `label` (string, up to 64 characters)
- `scopes` (array of Scope): Scopes to grant the new token, defaulting to read when omitted. You can grant only scopes that the calling token holds. A session token's all scope excludes permission to grant export.

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X POST "$API/tokens" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "address": "info@example.com",
    "expires_in": 1,
    "label": "my laptop",
    "scopes": [
      "read"
    ]
  }'
```

Response, 201 Created:

```
{
  "address": "info@example.com",
  "expires_at": "2026-09-16T10:15:00Z",
  "id": 1,
  "kind": "profile",
  "label": "my laptop",
  "scopes": [
    "read"
  ],
  "token": "ub_9f3c2a7e1b5d4082a6c1e7f0",
  "user": "alice"
}
```

## Errors

- 400: A <kind> token needs the client's address
- 400: A plugin's token names its scopes
- 400: A session is opened by a panel user: name one with --actor
- 400: A session opened for a user is a session
- 400: At least one scope is required
- 400: Invalid <what>: expected a non-negative integer
- 400: Invalid IPv4 address
- 400: Invalid IPv6 address
- 400: Invalid id
- 400: Invalid label: 1 to 64 printable ASCII characters
- 400: Invalid user agent: 1 to 255 printable ASCII characters
- 400: Invalid username: 2 to 32 lowercase letters, digits or underscores, starting with a letter
- 400: Unknown scope '<s>'; the scopes are 
- 400: Username '<value>' is reserved
- 401: Authentication required
- 403: <opener.name> may not open the panel of <owner>
- 403: Only a customer's panel is opened: <owner> is an administrator
- 403: User '<owner>' is suspended
- 403: your token cannot grant the scope <lacks>
- 404: User '
