Developers
Authentication
How the Crate API checks who is calling, how to send your API key, and how permissions decide what a request may do.
Reviewed
On this page
Every API request must carry an API key. The key tells Crate which store the request is for and what it is allowed to do.
Send the key as a bearer token
Put the key in the Authorization header, after the word Bearer and a space:
curl https://<crate-address>/api/v1/account \
-H "Authorization: Bearer crate_pat_your_key_here"- Send the key in the header only. Crate ignores a key in the address or the request body, and treats the request as having no key.
- Every API path starts with
/api/v1and every response is JSON. - The API has no sign-in session or cookies. Each request stands on its own.
One key, one store
A key belongs to the store it was created in. Crate works out the store from the key, never from the address you call. A key can't see another store's data. If you ask for a record from another store, you get 404 Not Found.
To see which store a key belongs to, call GET /api/v1/account. It needs no permission beyond a valid key. GET /api/v1/me returns the same answer.
Permissions (scopes)
Each key holds a list of scopes. There is a read scope and a write scope for each resource group, such as read_products and write_products.
| Request | Scope needed |
|---|---|
GET (read) |
read_<group> or write_<group>
|
POST, PUT, PATCH, DELETE (change) |
write_<group> |
A write scope includes the read scope for the same group. The permissions you choose in the dashboard map to scopes like this:
| In the dashboard | Scopes on the key |
|---|---|
| All | Every read_ and write_ scope |
| Read Only | Every read_ scope |
| Restricted | The Read and Write boxes you ticked |
A request outside the key's scopes is refused with 403 Forbidden and a message that names the missing scope:
{ "errors": "Token is missing the 'write_products' scope" }The scope each resource needs is listed in the API reference.
When a key stops working
A request with no usable key gets 401 Unauthorized:
| Message | Cause |
|---|---|
Missing bearer token |
No Authorization header, a header in the wrong format, or a key sent in the address. |
Invalid or expired access token |
The key is wrong, past its expiry date, or revoked. |
Expired and revoked keys can't be brought back. Create a new key on the API keys page.
OAuth applications
The API also accepts OAuth access tokens in the same Authorization: Bearer header. You can't register an OAuth application from the dashboard at launch, so use an API key for your integrations.
Keep keys safe
- Create one key per integration, and name it after the job. Then you can revoke one without breaking the others.
- Set an expiry on keys you only need for a project.
- Check Last used on the API keys page now and then. Revoke keys nobody uses.
- If a key leaks, revoke it straight away and create a new one.
Troubleshooting
Next steps
Was this helpful?
Still need a hand?
Tell us the task you were trying to complete and the message you saw. Include your store name or order reference when relevant. Keep passwords, API secrets and card details private.
Contact Crate