API reference (v1)
A small, stable JSON API for integrations, the mobile apps and offline sync. It uses the same rules as the app — permissions, location limits and stock integrity are enforced identically.
The full contract, every endpoint, field and webhook, is described in OpenAPI 3.1: openapi.yaml or openapi.json. Load it into an API tool or a client generator to get typed code in your language.
Authentication
Create a token in Settings › API & webhooks. Send it as a bearer token. Tokens belong to one organization and one person, carry scopes, can expire, and can be revoked at any time. A token stops working if its owner is removed or suspended.
curl https://magpieinventory.com/api/v1/me -H "Authorization: Bearer mgp_…"
Scopes: read, write (items), stock (adjust/move), counts, sync.
Conventions
- Quantities and money are strings (exact decimals), e.g.
"12.5". - Pagination:
?limit=100&after=<id>→meta.has_more,meta.next_after(max 500). - Rate limit: 600 requests per minute per token (
429when exceeded). - Errors:
{"error": {"code": "...", "message": "...", "details": {...}}}with codesunauthorized,forbidden,not_found,invalid,insufficient_stock,stale_quantity,idempotency_conflict,rate_limited. - Stock-changing requests require an
Idempotency-Keyheader. Retrying with the same key returns the original result; the same key with different details returns409 idempotency_conflict.
Endpoints
Swipe the table left to see more columns.
| Endpoint | Scope | Description |
|---|---|---|
GET /me | any | Token, user, organization and permissions |
GET /items | read | List items (q, updated_since, include_archived) |
GET /items/:id | read | Item with stock by location and minimums (each location's own minimum, with on_hand including places inside it) |
POST /items | write | Create (item{…}, optional initial_quantity, location_id, barcode; Idempotency-Key) |
PATCH /items/:id | write | Update item details (never quantities) |
PUT /items/:id/minimums/:location_id | write | Set a location's minimum: minimum{min_quantity, reorder_quantity}. 201 when new, 200 when changed |
DELETE /items/:id/minimums/:location_id | write | Remove a location's minimum |
GET /locations | read | Locations you can see |
GET /stock_levels | read | Balances (item_id, location_id) |
POST /adjustments | stock | item_id, location_id, change (add|remove|set), quantity, reason, note, expected_quantity. When the organization requires approval for this member: 202 Accepted with approval_request (status: "pending", quantity_change, …) and no stock change; a retry returns it with 200. |
POST /transfers | stock | item_id, from_location_id, to_location_id, quantity, note |
POST /scans | read | Resolve a scanned code to an item, serial or location |
GET /stock_counts, /stock_counts/:id | counts | Active counts and lines (expected quantities hidden for blind counts) |
POST /stock_counts/:id/entries | counts | Record a count entry (client_uuid required; line_id or code+location_id). A pack's barcode counts the whole pack; packs: {"<pack id>": 3, "each": 2} counts in packs (the server works out the total). Items and count lines list their packs |
GET /sync/snapshot?count_id= | sync | Everything needed to count offline |
GET /sync/changes?since= | sync | Changed items/locations/counts plus deletions |
POST /sync/mutations | sync | Ordered batch of offline operations |
Offline sync
Each offline operation has a client-generated id that is its idempotency key. Submit operations in the order they were recorded:
POST /api/v1/sync/mutations
{ "sent_at": "2026-11-11T15:00:00Z",
"mutations": [
{ "id": "7d0c…", "type": "count_entry.create", "recorded_at": "…", "payload": { "count_id": 12, "line_id": 340, "quantity": "1" } },
{ "id": "1a9e…", "type": "adjustment.create", "payload": { "item_id": 5, "location_id": 2, "change": "set", "quantity": "8", "expected_quantity": "10", "note": "recount" } }
] }
Each result is applied, conflict (needs a person — e.g. the quantity changed since the device saw it, or the count was closed) or rejected (invalid or not permitted). Replays return the stored result. Quantities are applied as changes, never last-write-wins; an offline “set” must include the quantity the device last saw. Device times are corrected for clock skew using sent_at.
An adjustment.create that needs approval is applied (accepted; the answer won't change) with data.approval_status: "pending", data.adjustment_request_id and data.changed: false. Stock changes when someone approves it; subscribe to adjustment_request.status_changed to hear the decision.
Webhooks
Events: stock.changed, item.low_stock, stock_count.completed, purchase_order.status_changed, checkout.overdue, adjustment_request.status_changed. item.low_stock carries location_id and location when a location's own minimum was reached. Verify every delivery:
X-Webhook-Signature: t=1700000000,v1=<hex>
expected = HMAC_SHA256(secret, "#{t}.#{raw_body}")
reject if |now - t| > 300 seconds, or v1 != expected (constant-time compare)
Failed deliveries retry with exponential backoff (8 attempts). Use X-Webhook-Id to ignore duplicates.