API introduction
Authentication
On this page
Every request needs an API key. A key belongs to one store and is made in that store's admin, by its Super Admin. It only works on that store's own address.
Send your key#
Send the key in a header, in one of two ways. Use either one.
Authorization: Bearer YOUR_API_KEY
X-Api-Key: YOUR_API_KEYThe key is read from the headers only. Never put it in the address (the query string) of a request, where it would be saved in logs and browser history.
Get a key#
- In the admin open Settings > API & webhooks > API keys and press Create API key. A Super Admin does this.
- Give the key a name that says what uses it (for example "Accounting sync"), tick only the permissions it needs, and optionally set an allowed-address list, an expiry date and a limit of requests per minute.
- Copy the key when it is shown. It is shown only once. Only a scrambled copy is stored, so a lost key cannot be looked up: rotate the key to get a new secret. The admin keeps showing the first few characters of the key, so you can tell your keys apart.
- Give the key to the person who will use it in a safe way: a password manager or a secret manager, not a chat message or an email.
Scopes#
A key can only do what its scopes allow. A call that needs a scope the key does not have is refused with 403 and error.code = "insufficient_scope"; error.required_scope names the missing scope.
| Scope | What it allows | Calls |
|---|---|---|
read:products | List and read products, their sizes, prices, HSN and GST rate. | GET/productsGET/products/{id}GET/products/{id}/variants |
write:productswrite | Create draft products and change name, description, category, HSN, GST rate, sizes and prices. It can publish only a complete product and can never delete: removing a product archives it. | POST/productsPATCH/products/{id}DELETE/products/{id}POST/products/{id}/variantsPATCH/products/{id}/variants/{variantId} |
read:orders | List and read orders, including the customer name, contact details and delivery address (needed to ship an order). | GET/ordersGET/orders/{number} |
write:orderswrite | Move an order to its next status, add shipment details (courier, AWB, tracking link) and internal notes. It never marks an order paid and never refunds. | PATCH/orders/{number}POST/orders/{number}/shipmentPOST/orders/{number}/notes |
read:inventory | Read stock levels (on hand, reserved, available, reorder level) and the stock history. | GET/inventoryGET/inventory/movements |
write:inventorywrite | Add, remove or set stock with a reason. Every change goes into the stock history, with the key as the author. | POST/inventory/adjustments |
read:customers | Read your contact list (customers, leads, subscribers). Email and phone are hidden unless the key also has the personal details option. | GET/customersGET/customers/{id} |
read:categories | Read the product categories. | GET/categoriesGET/categories/{id} |
- A key can never be given more than the person who creates it can do. Write scopes and the personal details option can only be given by a Super Admin.
- Keys created before scopes were introduced (update 1.0.65) have only
read:productsandread:orders. - Nothing here can refund an order, take a payment or touch coupons: those calls do not exist.
The personal details option#
By default the customers list hides contact details: emails and phone numbers are masked (for example b***@example.com and ********0000). A key with the Show customers' personal details option sees them in full. Only a Super Admin can switch the option on or off.
Orders are different: an order always includes the customer's name, contact details and delivery address, because shipping needs them. Give read:orders only to keys that need it. Webhooks have their own setting for personal details on each endpoint (see Webhooks).
Options of a key#
- Allowed addresses (optional): the key then works only from these internet addresses (IPv4, IPv6 or ranges such as 203.0.113.0/24, up to 50 entries). Outside them the answer is 403
ip_not_allowed. Empty means any address. If the store sits behind a CDN or a proxy, the store has a hosting setting for how visitors reach the server, and it must be set, otherwise the store sees the proxy's address and not yours. - Expiry date (optional): the key works until the end of that day and then stops (401
expired_api_key). Not set means the key never expires. - Requests per minute: see Rate limits and key limits.
- Pause switches a key off for now and can be undone (403
api_key_disabled). Revoke is permanent (401revoked_api_key). Rotate secret makes a new secret and the old one stops at once, so have the new one ready to deploy. For a change without a gap, create a second key, move your software to it, and then revoke the first.
Keep keys safe#
Important
A key is a password for your store's data. Never share a key, and never put one in a web page, a mobile app, a public code repository, a screenshot or an email to support.
- Give each system its own key, with the narrowest scopes it needs, so one key can be rotated or revoked without disturbing the others.
- Keep keys in your server's secret settings or environment variables, not in your code.
- If a key may have leaked, rotate it at once in the admin (the old secret stops working immediately) and update the software that uses it.
- Use an allowed-address list for servers with a fixed address, and an expiry date for temporary work.
- Every key's calls are listed in the admin under API & webhooks > Request log (the address called, the result and the time; never what was sent or returned). Look at it now and then: a call you do not recognise means the key should be rotated.
- The Security best practices page has the full list.
Authentication errors#
| Code | HTTP status | Meaning |
|---|---|---|
missing_api_key | 401 | No key was sent. Use "Authorization: Bearer KEY" or the X-Api-Key header. |
invalid_api_key | 401 | The key is not valid. Check you copied all of it. |
revoked_api_key | 401 | The key was revoked in the admin. Create a new one. |
expired_api_key | 401 | The key passed its expiry date. |
api_key_disabled | 403 | The key is paused in the admin. |
ip_not_allowed | 403 | The key has an IP allow-list and your address is not on it. |
insufficient_scope | 403 | The key does not have the scope this call needs. error.required_scope names it. |
too_many_failed_attempts | 429 | Too many invalid keys from your address. Wait for Retry-After. |