All guides
The API and webhooks
Connect your other systems to Magpie with API tokens, and hear about changes the moment they happen with signed webhooks.
After reading this guide, you'll know:
- What the API can do, and where to find the full reference.
- How to create, scope and revoke API tokens.
- How to add a webhook and choose its events.
- How to check that a webhook really came from Magpie, and what happens when deliveries fail.
On this page
The API lets your own systems read and change your inventory, and webhooks tell them when something happens. Both are set up under Settings › API & webhooks, by people whose role lets them manage API tokens and webhooks (owners and admins).
1 What the API does
The API is a small JSON API at /api/v1. It follows the same rules as the app: permissions, location limits, approvals and stock checks all apply. With it you can:
- read items, locations and stock levels,
- create items and update their details (quantities only change through stock changes),
- set or remove a location's minimum for an item,
- add, remove, correct and move stock (a change that needs approval waits for it, like any other),
- look up a scanned code,
- read active counts and record count entries.
The Magpie phone apps use the same API to count offline.
The API reference covers authentication, conventions, every endpoint and the error codes. There's also a link to it, API documentation, at the top of Settings › API & webhooks.

2 Create an API token
Every request needs a token. Give each integration its own, with only the scopes it needs, so you can revoke one without breaking the others.
- Under API tokens, type a Name that says what it's for.
- Choose when it Expires: In 90 days, In 30 days, In a year or Never.
- Tick its Scopes (see below).
- Choose Create token.
- Copy the token straight away and keep it somewhere safe. Magpie shows it only once.
| Scope | What it allows |
|---|---|
read | Read items, locations, stock and reports |
write | Create and update items and locations |
stock | Post stock adjustments and moves |
counts | Record stock count entries |
sync | Offline synchronization |
A token acts as the person who created it. Their role's permissions and location limit apply as well as the token's scopes, and their name is on every change it makes. If they're removed from the organization or suspended, their tokens stop working.
3 Revoke a token
The list under API tokens shows each token's name and first few characters, its scopes, who created it, when it was last used and when it expires. Choose Revoke and confirm, and it stops working straight away; it stays in the list marked Revoked. A token that expires stops working on its own.
4 Add a webhook
A webhook sends a message to your system each time something happens, so it doesn't have to keep asking.
- Under Webhooks, type the Endpoint URL. It must start with
https://and be reachable from the internet. - Tick the Events to send, at least one.
- Choose Add webhook.
The confirmation shows the webhook's signing secret, which starts with whsec_. Copy it into your receiving system now: you need it to check signatures, and it isn't shown again.
| Event | When it's sent |
|---|---|
stock.changed | Stock changed (any adjustment, move, receipt, count, pick…) |
item.low_stock | Item fell to or below a minimum (for all locations or one) |
stock_count.completed | A count was completed |
purchase_order.status_changed | A purchase order changed status |
adjustment_request.status_changed | A stock change was requested, approved, rejected or withdrawn |
checkout.overdue | A check-out became overdue |
Each message is a JSON POST with the event's id, type, created_at, your organization and the event's data. The API reference has the details.
5 Check the signature
Anyone can send a request to your URL, so check that each one came from Magpie before you act on it. Every message has an X-Webhook-Signature header like t=1700000000,v1=…:
- Work out the HMAC-SHA256 of the timestamp, a dot and the raw body (
t.body), using your signing secret. - Compare it with
v1, using a constant-time comparison. - Reject the message if they differ, or if the timestamp is more than 5 minutes old.
The X-Webhook-Id header is the same each time a message is retried, so you can ignore one you've already handled.
6 When deliveries fail
Reply quickly with a 2xx status: Magpie waits up to 10 seconds. If your system doesn't answer or replies with an error, Magpie tries again later, waiting longer each time, up to 8 attempts.
Recent deliveries lists the latest 20 messages, with whether each was delivered or failed, the event, how many attempts it took and the HTTP status your system replied with.
If 20 messages in a row fail, Magpie stops sending to that webhook and it's marked disabled after repeated failures. Fix the problem, then Remove the webhook and add it again. The new one has a new signing secret.
7 Sign out mobile devices
When people sign in to the Magpie phone apps for offline counting, each phone gets its own sign-in for syncing. They're listed under Mobile devices, with the device, the person and when it was last active. Choose Sign out to end one, for example when a phone is lost. Removing or suspending a person signs out their devices too.
Still stuck?
Email support with what you were trying to do and any message you saw.