Tokens, scopes and authentication
Send the token
Send the token in the Authorization header of every request:
Authorization: Bearer <your API token>
An integration always authenticates this way: no cookie, no session and no sign-in step.
What a token may do
A token acts as the person who created it, inside that person’s business. Three rules decide every request:
- The operation must be open to tokens. Only the operations in the product’s reference
are. Any other route answers
401withdata.codeAPI_TOKEN_SCOPE_DENIED. - The token’s scopes must cover it. Each operation names the scope it needs; when several
are listed, any one is enough. Without it:
403API_TOKEN_SCOPE_DENIED. - The token’s owner must still be allowed now. A scope never gives more than its owner
holds. When the owner’s role changes, the token follows at once. When the owner is no longer
allowed:
403ACCESS_DENIED.
Each record or action also keeps its own rules, such as plan limits or a business feature that is switched off. The reference notes them per operation.
Scopes and presets
A scope is a permission key, for example page:orders:view to read the orders screen.
Running an action needs the screen’s create key without an id in the body, and its edit key
with one. The reference lists the exact key or keys for every operation.
A preset is a named group of scopes, stored on the token as preset:<name>. Changing a preset’s
keys later changes every token that holds it. Each product’s reference lists its presets.
Give each system its own token with the fewest scopes it needs. A form that only adds enquiries needs no read scope at all.
Expiry, regeneration and revoking
| What | How | Effect |
|---|---|---|
| Expiry | Expires At when you create or edit the token | After that date the token answers 401 API_TOKEN_OWNER_INACTIVE. |
| Regenerate | Regenerate on the token’s row | A new secret with the same name, scopes and expiry. The old secret stops working at once. Only the person who created the token can regenerate it, because its requests run as that person. |
| Revoke | Revoke on the token’s row | The token stops working for good. It can’t be regenerated; create a new token instead. |
A token also stops working when its owner can no longer sign in. Then every request answers
401 API_TOKEN_OWNER_INACTIVE.
Keep tokens safe
- Keep tokens on your server only. Never in a browser, a mobile app or a git repository.
- Use one token per system, so you can revoke one without stopping the others.
- Regenerate a token at once if it may have leaked, then update the system that uses it.