Authentication & scopes

Tokens belong to an organisation, not to a person. They carry scopes, can be bound to specific sandboxes, and can expire.

Tokens

An organisation admin creates a token under Settings → Organisations → your organisation → API tokens. The token is shown once. It belongs to the organisation: it keeps working after the person who created it leaves, and it reaches exactly that organisation — never another one its creator happens to be a member of.

Send it as a bearer token on every request:

Authorization: Bearer 12|kB3s...redacted
Accept: application/json

A token is a secret with the reach of the organisation. Put it in a repository secret or a vault, never in code, and give it an expiry when it lives in CI.

Scopes

A token holds one or more scopes, named resource:verb. Each endpoint requires one; a request without it is refused with 403. Grant what the script does and nothing more — a job that only reads mail does not need emails:purge.

API token scopes and what each one grants
ScopeGrants
sandboxes:readList sandboxes, read one with its SMTP credentials
sandboxes:createCreate sandboxes, permanent or ephemeral
sandboxes:deleteDelete a sandbox
emails:readList, search, read and download emails and attachments; wait and expect
emails:deleteDelete a single email
emails:purgeEmpty a sandbox
analysis:runDeliverability and authentication analysis; the deliverability_at_least check of expect
shares:createCreate a public share link to an email
webhooks:readList webhooks and their delivery history
webhooks:writeCreate, update and delete webhooks

The original two abilities

Tokens created before the scope grammar carried read and purge. They keep working forever: read means sandboxes:read plus emails:read, and purge means emails:purge. They never meant anything else, so a legacy read token cannot delete a single email or run the analysis.

Binding a token to sandboxes

By default a token reaches every sandbox of the organisation, including ones created later. When you create it you can restrict it to a list of sandboxes instead. Everything outside that list answers 404, exactly like a sandbox of another organisation, and the sandbox listing shows only the bound ones.

A bound token cannot create sandboxes: the sandbox it would create is outside its own reach, which is a credential nobody can use. Use an unbound token — or one with only sandboxes:create and the read scopes — for the job that creates per-run sandboxes.

Expiry

A token can be given an expiry of 30 days, 90 days or a year. After that every request with it answers 401. Revoking it from the settings screen has the same effect, at once. The screen shows when each token was last used, so an unused one is easy to spot and remove.

What the status codes mean

Authentication status codes and their meaning
StatusMeaning
401No token, a malformed or revoked one, an expired one, or a token whose organisation was deleted
403The token lacks the scope the endpoint requires, or is bound to sandboxes and tried to create one
404The identifier does not exist, or belongs to a sandbox or organisation the token does not reach

The last row is deliberate: a token cannot be used to discover which identifiers exist. The rest of the error format is in Conventions.