{"openapi":"3.1.0","info":{"title":"Magpie API","version":"1","summary":"Items, stock, counts and offline sync for one organization.","description":"A small, stable JSON API for integrations, the mobile apps and offline sync. It calls the same rules as the app:\npermissions, location limits and stock integrity are enforced identically.\n\n**Quantities and money are strings** holding exact decimals, such as `\"12.5\"`, never JSON numbers.\n\n**Pagination** is by keyset: `?limit=100&after=<id>`, then follow `meta.next_after` while `meta.has_more` is true.\n`limit` is at most 500.\n\n**Rate limit:** 600 requests a minute per token; more get `429` with the code `rate_limited`.\n\n**Stock-changing requests** need an `Idempotency-Key` header (or an `idempotency_key` parameter). Retrying with\nthe same key returns the original result; the same key with different details returns `409 idempotency_conflict`.\n","license":{"name":"AGPL-3.0-only","identifier":"AGPL-3.0-only"}},"servers":[{"url":"https://magpieinventory.com/api/v1","description":"Magpie"}],"security":[{"token":[]}],"tags":[{"name":"Account"},{"name":"Items"},{"name":"Locations"},{"name":"Stock"},{"name":"Scanning"},{"name":"Counts"},{"name":"Sync","description":"Offline synchronization for the mobile apps (docs/ARCHITECTURE.md, Offline)."}],"paths":{"/me":{"get":{"tags":["Account"],"operationId":"getMe","summary":"The token, its person, the organization and their permissions","description":"Works with any scope.","responses":{"200":{"description":"Who the token acts as.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Me"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/items":{"get":{"tags":["Items"],"operationId":"listItems","summary":"List items","description":"Scope: `read`. Active items, oldest first, unless `include_archived=true`.","parameters":[{"name":"q","in":"query","description":"Search by name, code, SKU or barcode.","schema":{"type":"string"}},{"$ref":"#/components/parameters/UpdatedSince"},{"$ref":"#/components/parameters/IncludeArchived"},{"$ref":"#/components/parameters/Limit"},{"$ref":"#/components/parameters/After"}],"responses":{"200":{"description":"A page of items.","content":{"application/json":{"schema":{"type":"object","required":["data","meta"],"properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Item"}},"meta":{"$ref":"#/components/schemas/PageMeta"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"429":{"$ref":"#/components/responses/RateLimited"}}},"post":{"tags":["Items"],"operationId":"createItem","summary":"Create an item","description":"Scope: `write`, and permission to manage items. With `initial_quantity` and `location_id`, the item starts\nwith that stock; when the organization requires approval for this person, the starting stock is requested\ninstead and returned as `starting_stock_request`.\n","parameters":[{"$ref":"#/components/parameters/IdempotencyKey"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["item"],"properties":{"item":{"allOf":[{"$ref":"#/components/schemas/ItemInput"},{"required":["name"]}]},"initial_quantity":{"$ref":"#/components/schemas/QuantityInput"},"location_id":{"type":"integer","description":"Where the starting stock is."},"barcode":{"type":"string","description":"A barcode to add to the item."}}}}}},"responses":{"201":{"description":"The new item.","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"$ref":"#/components/schemas/Item"},"starting_stock_request":{"$ref":"#/components/schemas/AdjustmentRequest"}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"409":{"$ref":"#/components/responses/Conflict"},"422":{"$ref":"#/components/responses/Unprocessable"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/items/{id}":{"parameters":[{"$ref":"#/components/parameters/Id"}],"get":{"tags":["Items"],"operationId":"getItem","summary":"An item, with its stock by location and each location's own minimum","description":"Scope: `read`. `stock` lists non-zero balances in locations the token's person can see.","responses":{"200":{"description":"The item.","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"$ref":"#/components/schemas/ItemDetail"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"429":{"$ref":"#/components/responses/RateLimited"}}},"patch":{"tags":["Items"],"operationId":"updateItem","summary":"Update an item's details","description":"Scope: `write`, and permission to manage items. Never changes quantities: use adjustments, transfers or\ncounts. `PUT` does the same.\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["item"],"properties":{"item":{"$ref":"#/components/schemas/ItemInput"}}}}}},"responses":{"200":{"description":"The updated item.","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"$ref":"#/components/schemas/Item"}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"422":{"$ref":"#/components/responses/Unprocessable"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/items/{item_id}/minimums/{location_id}":{"parameters":[{"name":"item_id","in":"path","required":true,"schema":{"type":"integer"}},{"name":"location_id","in":"path","required":true,"schema":{"type":"integer"}}],"put":{"tags":["Items"],"operationId":"setMinimum","summary":"Set a location's own minimum for an item","description":"Scope: `write`, and permission to manage items in that location.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["minimum"],"properties":{"minimum":{"type":"object","properties":{"min_quantity":{"$ref":"#/components/schemas/QuantityInput"},"reorder_quantity":{"$ref":"#/components/schemas/QuantityInput"}}}}}}}},"responses":{"200":{"description":"The minimum was changed.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ReorderLevelResponse"}}}},"201":{"description":"The location had no minimum for this item; now it does.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ReorderLevelResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"422":{"$ref":"#/components/responses/Unprocessable"},"429":{"$ref":"#/components/responses/RateLimited"}}},"delete":{"tags":["Items"],"operationId":"removeMinimum","summary":"Remove a location's own minimum for an item","description":"Scope: `write`, and permission to manage items in that location.","responses":{"204":{"description":"Removed."},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/locations":{"get":{"tags":["Locations"],"operationId":"listLocations","summary":"Locations the token's person can see","description":"Scope: `read`.","parameters":[{"$ref":"#/components/parameters/UpdatedSince"},{"$ref":"#/components/parameters/IncludeArchived"},{"$ref":"#/components/parameters/Limit"},{"$ref":"#/components/parameters/After"}],"responses":{"200":{"description":"A page of locations.","content":{"application/json":{"schema":{"type":"object","required":["data","meta"],"properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Location"}},"meta":{"$ref":"#/components/schemas/PageMeta"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/stock_levels":{"get":{"tags":["Stock"],"operationId":"listStockLevels","summary":"Stock balances","description":"Scope: `read`. Non-zero balances in locations the token's person can see, unless `include_zero=true`.","parameters":[{"name":"item_id","in":"query","schema":{"type":"integer"}},{"name":"location_id","in":"query","description":"A location; places inside it are included.","schema":{"type":"integer"}},{"name":"include_zero","in":"query","schema":{"type":"string","enum":["true","false"]}},{"$ref":"#/components/parameters/Limit"},{"$ref":"#/components/parameters/After"}],"responses":{"200":{"description":"A page of balances.","content":{"application/json":{"schema":{"type":"object","required":["data","meta"],"properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/StockLevel"}},"meta":{"$ref":"#/components/schemas/PageMeta"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/adjustments":{"post":{"tags":["Stock"],"operationId":"adjustStock","summary":"Add, remove or set an item's stock in a location","description":"Scope: `stock`. When the organization requires approval for this person, nothing changes yet: the response is\n`202` with `approval_request`, and a retry with the same key returns it with `200`. Subscribe to the\n`adjustment_request.status_changed` webhook to hear the decision.\n","parameters":[{"$ref":"#/components/parameters/IdempotencyKey"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["item_id","location_id","change","quantity"],"properties":{"item_id":{"type":"integer"},"location_id":{"type":"integer"},"change":{"type":"string","enum":["add","remove","set"]},"quantity":{"$ref":"#/components/schemas/QuantityInput","description":"How many to add or remove, or the new quantity for `set`."},"reason":{"type":"string","description":"For `add`: receipt, found, return, correction or initial. For `remove`: usage, damage, loss,\ncorrection, expired, spoiled, spilled or made_wrong. For `set`: correction.\n"},"note":{"type":"string","description":"Required for `set`."},"expected_quantity":{"$ref":"#/components/schemas/QuantityInput","description":"The quantity you last saw. If stock has moved since, the request fails with `stale_quantity`."},"lot_id":{"type":"integer"},"lot_number":{"type":"string","description":"For items tracked by lot","adding to a new or existing lot.":null},"serial_unit_ids":{"type":"array","items":{"type":"integer"},"description":"For serialized items."}}}}}},"responses":{"200":{"description":"A retry with the same key; the original result.","content":{"application/json":{"schema":{"anyOf":[{"$ref":"#/components/schemas/StockOperationResult"},{"$ref":"#/components/schemas/ApprovalPending"}]}}}},"201":{"description":"Stock changed (or `changed` is false when it was already right).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/StockOperationResult"}}}},"202":{"description":"Waiting for approval; stock hasn't changed.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApprovalPending"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"409":{"$ref":"#/components/responses/Conflict"},"422":{"$ref":"#/components/responses/Unprocessable"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/transfers":{"post":{"tags":["Stock"],"operationId":"transferStock","summary":"Move stock between locations","description":"Scope: `stock`.","parameters":[{"$ref":"#/components/parameters/IdempotencyKey"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["item_id","from_location_id","to_location_id","quantity"],"properties":{"item_id":{"type":"integer"},"from_location_id":{"type":"integer"},"to_location_id":{"type":"integer"},"quantity":{"$ref":"#/components/schemas/QuantityInput"},"note":{"type":"string"},"lot_id":{"type":"integer"},"serial_unit_ids":{"type":"array","items":{"type":"integer"}}}}}}},"responses":{"200":{"description":"A retry with the same key; the original result.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/StockOperationResult"}}}},"201":{"description":"Moved.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/StockOperationResult"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"409":{"$ref":"#/components/responses/Conflict"},"422":{"$ref":"#/components/responses/Unprocessable"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/scans":{"post":{"tags":["Scanning"],"operationId":"resolveScan","summary":"Find what a scanned code is","description":"Scope: `read`. Resolves a barcode, QR code or typed code to an item, a serial unit or a location.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["code"],"properties":{"code":{"type":"string"},"symbology":{"type":"string","description":"The barcode type, if known (for example ean13 or qr)."}}}}}},"responses":{"200":{"description":"What the code is, if anything.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScanResult"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/stock_counts":{"get":{"tags":["Counts"],"operationId":"listStockCounts","summary":"Active counts the token's person counts or approves","description":"Scope: `counts`.","responses":{"200":{"description":"The counts.","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/StockCount"}}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/stock_counts/{id}":{"parameters":[{"$ref":"#/components/parameters/Id"}],"get":{"tags":["Counts"],"operationId":"getStockCount","summary":"A count and its lines","description":"Scope: `counts`. In a blind count, expected quantities are left out unless the person can approve counts.","responses":{"200":{"description":"The count.","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"$ref":"#/components/schemas/StockCountDetail"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/stock_counts/{id}/entries":{"parameters":[{"$ref":"#/components/parameters/Id"}],"post":{"tags":["Counts"],"operationId":"recordCountEntry","summary":"Record a count entry","description":"Scope: `counts`. Identify what was counted with `line_id`, or with `code` (and `location_id`), or with\n`item_id` and `location_id`. A pack's barcode counts the whole pack; `packs` counts in packs and the server\nworks out the total. Sending the same `client_uuid` again returns the first result with `replayed: true`.\nFor an item tracked by lot, the first answer may be `422 lot_needed` with the item's lots in `details`:\nsend the entry again with `lot_number` (and `lot_expires_on` for a new lot).\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["client_uuid"],"properties":{"client_uuid":{"type":"string","description":"Made by the client; makes the entry safe to retry."},"quantity":{"$ref":"#/components/schemas/QuantityInput","description":"Defaults to 1."},"mode":{"type":"string","enum":["add","set"],"default":"add"},"line_id":{"type":"integer"},"item_id":{"type":"integer"},"location_id":{"type":"integer"},"code":{"type":"string","description":"A scanned code."},"symbology":{"type":"string"},"source":{"type":"string","enum":["scan","manual","offline","import"],"default":"manual"},"recorded_at":{"type":"string","format":"date-time","description":"When it was counted","by the device's clock.":null},"sent_at":{"type":"string","format":"date-time","description":"When it was sent","by the device's clock; corrects for clock skew.":null},"packs":{"type":"object","description":"Counts by pack: `{\"<pack id>\": 3, \"each\": 2}`.","additionalProperties":{"$ref":"#/components/schemas/QuantityInput"}},"lot_number":{"type":"string"},"lot_expires_on":{"type":"string","format":"date"}}}}}},"responses":{"200":{"description":"The entry's result.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CountEntryResult"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"409":{"$ref":"#/components/responses/Conflict"},"422":{"$ref":"#/components/responses/Unprocessable"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/sync/snapshot":{"get":{"tags":["Sync"],"operationId":"syncSnapshot","summary":"Everything needed to count offline","description":"Scope: `sync`. Only for a count the token's person is counting.","parameters":[{"name":"count_id","in":"query","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"The count, its lines and locations, and a cursor for `sync/changes`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SyncSnapshot"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/sync/changes":{"get":{"tags":["Sync"],"operationId":"syncChanges","summary":"What changed since a cursor","description":"Scope: `sync`. Items, locations and counts changed since `since`, plus deletions (`tombstones`). The window\noverlaps the cursor by a few seconds, so dedupe by `id` and `updated_at`. At most 1,000 items come back:\nwhen `truncated` is true, ask again with the new `cursor`.\n","parameters":[{"name":"since","in":"query","description":"The `cursor` from the last snapshot or changes. Leave it out to get everything.","schema":{"type":"string","format":"date-time"}}],"responses":{"200":{"description":"The changes and a new cursor.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SyncChanges"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/sync/mutations":{"post":{"tags":["Sync"],"operationId":"syncMutations","summary":"Apply operations recorded offline","description":"Scope: `sync`. Send operations in the order they were recorded, at most 200 at a time (any beyond 200 are\nignored). Each one's `id` is its idempotency key: a replay returns the stored result. Quantities are applied\nas changes, never last-write-wins, so an offline `set` must include the quantity the device last saw.\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["mutations"],"properties":{"sent_at":{"type":"string","format":"date-time","description":"When the batch was sent","by the device's clock.":null},"mutations":{"type":"array","items":{"$ref":"#/components/schemas/Mutation"}}}}}}},"responses":{"200":{"description":"One result per operation, in order.","content":{"application/json":{"schema":{"type":"object","required":["results"],"properties":{"results":{"type":"array","items":{"$ref":"#/components/schemas/MutationResult"}}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"429":{"$ref":"#/components/responses/RateLimited"}}}}},"webhooks":{"stock.changed":{"post":{"summary":"Stock changed (any adjustment, move, receipt, count, pick…)","parameters":[{"$ref":"#/components/parameters/WebhookId"},{"$ref":"#/components/parameters/WebhookSignature"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/WebhookEvent"},{"properties":{"type":{"const":"stock.changed"},"data":{"$ref":"#/components/schemas/Transaction"}}}]}}}},"responses":{"200":{"$ref":"#/components/responses/WebhookReceived"}}}},"item.low_stock":{"post":{"summary":"An item fell to or below a minimum","description":"`location_id` and `location` are there when a location's own minimum was reached.","parameters":[{"$ref":"#/components/parameters/WebhookId"},{"$ref":"#/components/parameters/WebhookSignature"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/WebhookEvent"},{"properties":{"type":{"const":"item.low_stock"},"data":{"type":"object","required":["item_id","name","quantity","min_quantity"],"properties":{"item_id":{"type":"integer"},"name":{"type":"string"},"quantity":{"$ref":"#/components/schemas/NullableQuantity"},"min_quantity":{"$ref":"#/components/schemas/NullableQuantity"},"location_id":{"type":"integer"},"location":{"type":"string","description":"The location's full path."}}}}}]}}}},"responses":{"200":{"$ref":"#/components/responses/WebhookReceived"}}}},"stock_count.completed":{"post":{"summary":"A count was completed","parameters":[{"$ref":"#/components/parameters/WebhookId"},{"$ref":"#/components/parameters/WebhookSignature"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/WebhookEvent"},{"properties":{"type":{"const":"stock_count.completed"},"data":{"type":"object","required":["stock_count_id","reference","transaction_id"],"properties":{"stock_count_id":{"type":"integer"},"reference":{"type":"string"},"transaction_id":{"type":["integer","null"],"description":"The stock change the count made","if any.":null}}}}}]}}}},"responses":{"200":{"$ref":"#/components/responses/WebhookReceived"}}}},"purchase_order.status_changed":{"post":{"summary":"A purchase order changed status","parameters":[{"$ref":"#/components/parameters/WebhookId"},{"$ref":"#/components/parameters/WebhookSignature"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/WebhookEvent"},{"properties":{"type":{"const":"purchase_order.status_changed"},"data":{"type":"object","required":["purchase_order_id","reference","status"],"properties":{"purchase_order_id":{"type":"integer"},"reference":{"type":"string"},"status":{"type":"string"}}}}}]}}}},"responses":{"200":{"$ref":"#/components/responses/WebhookReceived"}}}},"adjustment_request.status_changed":{"post":{"summary":"A stock change was requested, approved, rejected or withdrawn","parameters":[{"$ref":"#/components/parameters/WebhookId"},{"$ref":"#/components/parameters/WebhookSignature"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/WebhookEvent"},{"properties":{"type":{"const":"adjustment_request.status_changed"},"data":{"type":"object","required":["id","reference","status","item_id","location_id","change","quantity_change"],"properties":{"id":{"type":"integer"},"reference":{"type":"string"},"status":{"$ref":"#/components/schemas/AdjustmentRequestStatus"},"item_id":{"type":"integer"},"location_id":{"type":"integer"},"change":{"type":"string","enum":["add","remove","set"]},"quantity_change":{"$ref":"#/components/schemas/Quantity"},"requested_by_user_id":{"type":"integer"},"decided_by_user_id":{"type":["integer","null"]},"stock_transaction_id":{"type":["integer","null"]}}}}}]}}}},"responses":{"200":{"$ref":"#/components/responses/WebhookReceived"}}}},"checkout.overdue":{"post":{"summary":"A check-out became overdue","parameters":[{"$ref":"#/components/parameters/WebhookId"},{"$ref":"#/components/parameters/WebhookSignature"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/WebhookEvent"},{"properties":{"type":{"const":"checkout.overdue"},"data":{"type":"object","required":["checkout_id","item_id","holder","due_at"],"properties":{"checkout_id":{"type":"integer"},"item_id":{"type":"integer"},"holder":{"type":"string","description":"Who has it."},"due_at":{"type":["string","null"],"format":"date-time"}}}}}]}}}},"responses":{"200":{"$ref":"#/components/responses/WebhookReceived"}}}}},"components":{"securitySchemes":{"token":{"type":"http","scheme":"bearer","bearerFormat":"mgp_…","description":"Create a token in Settings › API & webhooks. A token belongs to one organization and one person, carries\nscopes (`read`, `write`, `stock`, `counts`, `sync`), can expire and can be revoked. It stops working if its\nperson is removed or suspended.\n"}},"parameters":{"Id":{"name":"id","in":"path","required":true,"schema":{"type":"integer"}},"Limit":{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":500,"default":100}},"After":{"name":"after","in":"query","description":"The `meta.next_after` of the previous page.","schema":{"type":"integer"}},"UpdatedSince":{"name":"updated_since","in":"query","description":"Only records changed after this time.","schema":{"type":"string","format":"date-time"}},"IncludeArchived":{"name":"include_archived","in":"query","schema":{"type":"string","enum":["true","false"]}},"WebhookId":{"name":"X-Webhook-Id","in":"header","required":true,"description":"The event's id, the same in every retry. Use it to ignore duplicates.","schema":{"type":"string"}},"WebhookSignature":{"name":"X-Webhook-Signature","in":"header","required":true,"description":"`t=<unix time>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with the endpoint's secret>`.","schema":{"type":"string","pattern":"^t=[0-9]+,v1=[0-9a-f]{64}$"}},"IdempotencyKey":{"name":"Idempotency-Key","in":"header","required":true,"description":"Any unique string up to 100 characters, made by the client for this operation. Can be sent as the\n`idempotency_key` parameter instead.\n","schema":{"type":"string","maxLength":100}}},"responses":{"BadRequest":{"description":"A required parameter is missing or malformed (`invalid`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"Unauthorized":{"description":"The token is missing, invalid, expired or revoked (`unauthorized`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"Forbidden":{"description":"The token lacks the scope, or its person lacks the permission or location (`forbidden`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"NotFound":{"description":"Not found, or not in a location the token's person can see (`not_found`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"Conflict":{"description":"`idempotency_conflict` (the key was used for something else), `stale_quantity` (stock moved since\n`expected_quantity`; `details.current_quantity`) or `conflict` (the count can't take entries now).\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"Unprocessable":{"description":"`invalid` (with field errors in `details` where there are some), `insufficient_stock`\n(`details.available`) or `lot_needed` (`details.lots`).\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"RateLimited":{"description":"More than 600 requests in a minute (`rate_limited`). Retry after a minute.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"WebhookReceived":{"description":"Any 2xx response means it was received. Anything else, or no answer, is retried with exponential backoff, up\nto 8 attempts.\n"}},"schemas":{"Quantity":{"type":"string","pattern":"^-?[0-9]+(\\.[0-9]+)?$","description":"An exact decimal as a string, such as \"8\", \"2.5\" or \"-3\". Never a JSON number.","examples":["12.5"]},"NullableQuantity":{"anyOf":[{"$ref":"#/components/schemas/Quantity"},{"type":"null"}]},"QuantityInput":{"description":"An exact decimal. Send it as a string (\"12.5\"); a JSON number is also accepted.","anyOf":[{"type":"string","pattern":"^[+-]?[0-9]*\\.?[0-9]+$"},{"type":"number"}]},"Money":{"anyOf":[{"type":"string","pattern":"^-?[0-9]+(\\.[0-9]+)?$","description":"An exact decimal as a string, in the organization's currency."},{"type":"null"}]},"Timestamp":{"type":"string","format":"date-time"},"NullableId":{"type":["integer","null"]},"Error":{"type":"object","required":["error"],"properties":{"error":{"type":"object","required":["code","message"],"properties":{"code":{"type":"string","enum":["unauthorized","forbidden","not_found","invalid","insufficient_stock","stale_quantity","idempotency_conflict","conflict","lot_needed","rate_limited"]},"message":{"type":"string"},"details":{"type":"object","description":"Field errors for `invalid`, or what the code names (`current_quantity`, `available`, `lots`)."}}}}},"PageMeta":{"type":"object","required":["has_more","next_after"],"properties":{"has_more":{"type":"boolean"},"next_after":{"$ref":"#/components/schemas/NullableId"}}},"Me":{"type":"object","required":["user","organization","role","permissions","token"],"properties":{"user":{"type":"object","required":["id","name","email"],"properties":{"id":{"type":"integer"},"name":{"type":"string"},"email":{"type":"string"}}},"organization":{"type":"object","required":["id","slug","name","currency","features"],"properties":{"id":{"type":"integer"},"slug":{"type":"string","description":"The organization's address in the app: /o/<slug>/."},"name":{"type":"string"},"currency":{"type":"string","description":"An ISO 4217 code","such as CAD.":null},"features":{"type":"array","items":{"type":"string"},"description":"The modules turned on."}}},"role":{"type":"string"},"permissions":{"type":"array","items":{"type":"string"}},"token":{"type":"object","required":["name","scopes","kind","expires_at"],"properties":{"name":{"type":"string"},"scopes":{"type":"array","items":{"type":"string","enum":["read","write","stock","counts","sync"]}},"kind":{"type":"string","enum":["personal","device","integration"]},"expires_at":{"type":["string","null"],"format":"date-time"}}}}},"Pack":{"type":"object","description":"How an item comes packed. `quantity` is in the item's unit.","required":["id","name","quantity","for_ordering"],"properties":{"id":{"type":"integer"},"name":{"type":"string"},"quantity":{"$ref":"#/components/schemas/Quantity"},"for_ordering":{"type":"boolean","description":"The pack it's ordered in."}}},"Item":{"type":"object","required":["id","number","code","name","sku","description","item_type","serialized","track_lots","unit","decimal_places","quantity_on_hand","min_quantity","reorder_quantity","price","folder_id","category_id","vendor_id","barcodes","tags","custom_fields","packs","archived","updated_at"],"properties":{"id":{"type":"integer"},"number":{"type":"integer","description":"The item's number within the organization."},"code":{"type":"string","description":"The item's own code","also on its label.":null},"name":{"type":"string"},"sku":{"type":["string","null"]},"description":{"type":["string","null"]},"item_type":{"type":"string","enum":["consumable","equipment"],"description":"A stocked item","or a tool or piece of equipment.":null},"serialized":{"type":"boolean","description":"Each unit has its own serial number."},"track_lots":{"type":"boolean"},"unit":{"type":["string","null"],"description":"The unit's abbreviation, such as ea or kg."},"decimal_places":{"type":"integer","description":"How many decimal places its quantities use."},"quantity_on_hand":{"$ref":"#/components/schemas/Quantity"},"min_quantity":{"$ref":"#/components/schemas/NullableQuantity"},"reorder_quantity":{"$ref":"#/components/schemas/NullableQuantity"},"price":{"$ref":"#/components/schemas/Money"},"cost":{"$ref":"#/components/schemas/Money","description":"Only there when the token's person may see costs."},"folder_id":{"$ref":"#/components/schemas/NullableId"},"category_id":{"$ref":"#/components/schemas/NullableId"},"vendor_id":{"$ref":"#/components/schemas/NullableId"},"barcodes":{"type":"array","items":{"type":"string"}},"tags":{"type":"array","items":{"type":"string"}},"custom_fields":{"type":"object","description":"The organization's custom fields","by key.":null},"packs":{"type":"array","items":{"$ref":"#/components/schemas/Pack"}},"archived":{"type":"boolean"},"updated_at":{"$ref":"#/components/schemas/Timestamp"}}},"ItemDetail":{"allOf":[{"$ref":"#/components/schemas/Item"},{"type":"object","required":["stock","minimums"],"properties":{"stock":{"type":"array","items":{"$ref":"#/components/schemas/StockLevel"}},"minimums":{"type":"array","description":"Each location's own minimum for the item.","items":{"$ref":"#/components/schemas/ReorderLevel"}}}}]},"ItemInput":{"type":"object","properties":{"name":{"type":"string"},"description":{"type":"string"},"sku":{"type":"string"},"item_type":{"type":"string","enum":["consumable","equipment"]},"folder_id":{"type":"integer"},"category_id":{"type":"integer"},"unit_id":{"type":"integer"},"vendor_id":{"type":"integer"},"cost":{"$ref":"#/components/schemas/QuantityInput"},"price":{"$ref":"#/components/schemas/QuantityInput"},"min_quantity":{"$ref":"#/components/schemas/QuantityInput"},"reorder_quantity":{"$ref":"#/components/schemas/QuantityInput"},"notes":{"type":"string"},"tag_names":{"type":"string","description":"Tags separated by commas."},"custom_field_values":{"type":"object","description":"Values for the organization's custom fields","by key.":null}}},"ReorderLevel":{"type":"object","description":"A location's own minimum for an item. `on_hand` includes places inside the location.","required":["item_id","location_id","min_quantity","reorder_quantity","on_hand","status","updated_at"],"properties":{"item_id":{"type":"integer"},"location_id":{"type":"integer"},"min_quantity":{"$ref":"#/components/schemas/Quantity"},"reorder_quantity":{"$ref":"#/components/schemas/NullableQuantity"},"on_hand":{"$ref":"#/components/schemas/Quantity"},"status":{"type":"string","enum":["ok","low","out"]},"updated_at":{"$ref":"#/components/schemas/Timestamp"}}},"ReorderLevelResponse":{"type":"object","required":["data"],"properties":{"data":{"$ref":"#/components/schemas/ReorderLevel"}}},"Location":{"type":"object","required":["id","name","path","kind","code","parent_id","archived","updated_at"],"properties":{"id":{"type":"integer"},"name":{"type":"string"},"path":{"type":"string","description":"The full path, such as Main warehouse › Aisle 3 › Shelf B."},"kind":{"type":"string","enum":["warehouse","store","building","room","area","aisle","shelf","bin","vehicle","job_site","other"]},"code":{"type":"string","description":"The location's own code","also on its label.":null},"parent_id":{"$ref":"#/components/schemas/NullableId"},"archived":{"type":"boolean"},"updated_at":{"$ref":"#/components/schemas/Timestamp"}}},"StockLevel":{"type":"object","required":["item_id","location_id","lot_id","quantity","updated_at"],"properties":{"item_id":{"type":"integer"},"location_id":{"type":"integer"},"lot_id":{"$ref":"#/components/schemas/NullableId"},"quantity":{"$ref":"#/components/schemas/Quantity"},"updated_at":{"$ref":"#/components/schemas/Timestamp"}}},"Transaction":{"type":"object","description":"One stock change, made of a movement per item and location.","required":["id","kind","note","occurred_at","user_id","movements"],"properties":{"id":{"type":"integer"},"kind":{"type":"string","description":"What made it, such as adjustment, transfer, receipt or count."},"note":{"type":["string","null"]},"occurred_at":{"$ref":"#/components/schemas/Timestamp"},"user_id":{"$ref":"#/components/schemas/NullableId"},"movements":{"type":"array","items":{"type":"object","required":["item_id","location_id","lot_id","serial_unit_id","reason","quantity_delta","quantity_after"],"properties":{"item_id":{"type":"integer"},"location_id":{"type":"integer"},"lot_id":{"$ref":"#/components/schemas/NullableId"},"serial_unit_id":{"$ref":"#/components/schemas/NullableId"},"reason":{"type":"string"},"quantity_delta":{"$ref":"#/components/schemas/Quantity"},"quantity_after":{"$ref":"#/components/schemas/Quantity"}}}}}},"StockOperationResult":{"type":"object","required":["data","replayed","changed"],"properties":{"data":{"anyOf":[{"$ref":"#/components/schemas/Transaction"},{"type":"null"}]},"replayed":{"type":"boolean","description":"A retry with the same key."},"changed":{"type":"boolean","description":"False when stock was already as asked."}}},"ApprovalPending":{"type":"object","required":["data","changed","replayed","approval_request"],"properties":{"data":{"type":"null"},"changed":{"const":false},"replayed":{"type":"boolean"},"approval_request":{"$ref":"#/components/schemas/AdjustmentRequest"}}},"AdjustmentRequestStatus":{"type":"string","enum":["pending","approved","rejected","cancelled"]},"AdjustmentRequest":{"type":"object","description":"A stock change waiting for, or decided by, an approver.","required":["id","reference","status","item_id","location_id","lot_id","change","reason","quantity","quantity_change","note","requested_by_user_id","decided_by_user_id","decided_at","decision_note","stock_transaction_id","created_at"],"properties":{"id":{"type":"integer"},"reference":{"type":"string"},"status":{"$ref":"#/components/schemas/AdjustmentRequestStatus"},"item_id":{"type":"integer"},"location_id":{"type":"integer"},"lot_id":{"$ref":"#/components/schemas/NullableId"},"change":{"type":"string","enum":["add","remove","set"]},"reason":{"type":"string"},"quantity":{"$ref":"#/components/schemas/Quantity"},"quantity_change":{"$ref":"#/components/schemas/Quantity"},"note":{"type":["string","null"]},"requested_by_user_id":{"type":"integer"},"decided_by_user_id":{"$ref":"#/components/schemas/NullableId"},"decided_at":{"type":["string","null"],"format":"date-time"},"decision_note":{"type":["string","null"]},"stock_transaction_id":{"$ref":"#/components/schemas/NullableId"},"created_at":{"$ref":"#/components/schemas/Timestamp"}}},"StockCount":{"type":"object","required":["id","reference","name","status","blind","scope","due_on","snapshot_at","progress","can_count"],"properties":{"id":{"type":"integer"},"reference":{"type":"string"},"name":{"type":"string"},"status":{"type":"string","enum":["draft","in_progress","in_review","completed","voided"]},"blind":{"type":"boolean","description":"Counters don't see expected quantities."},"scope":{"type":"object","description":"What's being counted (location_ids, folder_ids)."},"due_on":{"type":["string","null"],"format":"date"},"snapshot_at":{"type":["string","null"],"format":"date-time"},"progress":{"type":"object","required":["counted","total"],"properties":{"counted":{"type":"integer"},"total":{"type":"integer"}}},"can_count":{"type":"boolean","description":"The token's person is one of its counters."}}},"StockCountDetail":{"allOf":[{"$ref":"#/components/schemas/StockCount"},{"type":"object","required":["lines"],"properties":{"lines":{"type":"array","items":{"$ref":"#/components/schemas/CountLine"}}}}]},"CountLine":{"type":"object","required":["id","item_id","item_name","location_id","lot_id","counted_quantity","status","round","barcodes","item_code","packs"],"properties":{"id":{"type":"integer"},"item_id":{"type":"integer"},"item_name":{"type":"string"},"location_id":{"type":"integer"},"lot_id":{"$ref":"#/components/schemas/NullableId"},"counted_quantity":{"$ref":"#/components/schemas/NullableQuantity"},"expected_quantity":{"$ref":"#/components/schemas/NullableQuantity","description":"Left out in a blind count, unless the token's person can approve counts."},"status":{"type":"string","enum":["pending","counted","recount"]},"round":{"type":"integer"},"barcodes":{"type":"array","items":{"type":"string"}},"item_code":{"type":"string"},"packs":{"type":"array","items":{"allOf":[{"$ref":"#/components/schemas/Pack"},{"type":"object","required":["barcodes"],"properties":{"barcodes":{"type":"array","items":{"type":"string"},"description":"The pack's own barcodes."}}}]}}}},"CountEntryResult":{"type":"object","required":["status","replayed"],"properties":{"status":{"type":"string","enum":["ok","unknown","location"],"description":"`ok`: recorded. `unknown`: the code matched nothing (kept for review). `location`: a location's code; later entries count there."},"message":{"type":"string"},"replayed":{"type":"boolean"},"line":{"$ref":"#/components/schemas/CountLine"}}},"ScanResult":{"type":"object","required":["status","kind","value"],"properties":{"status":{"type":"string","enum":["found","unknown","invalid"]},"kind":{"type":["string","null"],"enum":["item","unit","location",null]},"value":{"type":"string","description":"The code as sent."},"item":{"$ref":"#/components/schemas/Item"},"serial_unit":{"type":"object","required":["id","serial_number","status"],"properties":{"id":{"type":"integer"},"serial_number":{"type":"string"},"status":{"type":"string","enum":["in_stock","checked_out","retired","lost"]}}},"location":{"$ref":"#/components/schemas/Location"}}},"SyncSnapshot":{"type":"object","required":["cursor","count","locations","permissions"],"properties":{"cursor":{"$ref":"#/components/schemas/Timestamp"},"count":{"$ref":"#/components/schemas/StockCountDetail"},"locations":{"type":"array","items":{"$ref":"#/components/schemas/Location"}},"permissions":{"type":"array","items":{"type":"string"}}}},"SyncChanges":{"type":"object","required":["cursor","truncated","items","locations","stock_counts","tombstones","membership"],"properties":{"cursor":{"$ref":"#/components/schemas/Timestamp"},"truncated":{"type":"boolean"},"items":{"type":"array","items":{"$ref":"#/components/schemas/Item"}},"locations":{"type":"array","items":{"$ref":"#/components/schemas/Location"}},"stock_counts":{"type":"array","items":{"type":"object","required":["id","status","updated_at"],"properties":{"id":{"type":"integer"},"status":{"type":"string"},"updated_at":{"$ref":"#/components/schemas/Timestamp"}}}},"tombstones":{"type":"array","description":"Records deleted since the cursor.","items":{"type":"object","required":["type","id"],"properties":{"type":{"type":"string"},"id":{"type":"integer"}}}},"membership":{"type":"object","required":["active","permissions","restricted_location_ids"],"properties":{"active":{"type":"boolean"},"permissions":{"type":"array","items":{"type":"string"}},"restricted_location_ids":{"type":"array","items":{"type":"integer"},"description":"The locations the person is limited to; empty when they aren't limited."}}}}},"Mutation":{"type":"object","required":["id","type","payload"],"properties":{"id":{"type":"string","maxLength":100,"description":"Made by the device; the operation's idempotency key."},"type":{"type":"string","enum":["count_entry.create","adjustment.create","transfer.create"]},"recorded_at":{"type":"string","format":"date-time"},"payload":{"description":"The operation, by `type`.","anyOf":[{"$ref":"#/components/schemas/CountEntryPayload"},{"$ref":"#/components/schemas/AdjustmentPayload"},{"$ref":"#/components/schemas/TransferPayload"}]}}},"CountEntryPayload":{"type":"object","required":["count_id"],"properties":{"count_id":{"type":"integer"},"line_id":{"type":"integer"},"item_id":{"type":"integer"},"location_id":{"type":"integer"},"code":{"type":"string"},"quantity":{"$ref":"#/components/schemas/QuantityInput"},"mode":{"type":"string","enum":["add","set"]},"packs":{"type":"object","additionalProperties":{"$ref":"#/components/schemas/QuantityInput"}},"lot_number":{"type":"string"},"lot_expires_on":{"type":"string","format":"date"}}},"AdjustmentPayload":{"type":"object","required":["item_id","location_id","change","quantity"],"properties":{"item_id":{"type":"integer"},"location_id":{"type":"integer"},"change":{"type":"string","enum":["add","remove","set"]},"quantity":{"$ref":"#/components/schemas/QuantityInput"},"reason":{"type":"string"},"note":{"type":"string"},"expected_quantity":{"$ref":"#/components/schemas/QuantityInput","description":"Required for `set` offline."},"lot_number":{"type":"string"}}},"TransferPayload":{"type":"object","required":["item_id","from_location_id","to_location_id","quantity"],"properties":{"item_id":{"type":"integer"},"from_location_id":{"type":"integer"},"to_location_id":{"type":"integer"},"quantity":{"$ref":"#/components/schemas/QuantityInput"},"note":{"type":"string"}}},"MutationResult":{"type":"object","required":["id","status"],"properties":{"id":{"type":"string"},"status":{"type":"string","enum":["applied","conflict","rejected"],"description":"`applied`: done, or accepted for approval (`data.approval_status: \"pending\"`). `conflict`: needs a person,\nsuch as when stock moved since the device saw it, or the count was closed. `rejected`: invalid or not\npermitted.\n"},"code":{"type":"string","enum":["forbidden","stale_quantity","insufficient_stock","count_closed","not_found","invalid"]},"message":{"type":"string"},"replayed":{"type":"boolean","description":"The stored result of an operation already received."},"current_quantity":{"$ref":"#/components/schemas/Quantity"},"available":{"$ref":"#/components/schemas/Quantity"},"data":{"type":"object","description":"What it did, by type.","properties":{"entry_status":{"type":"string","enum":["ok","unknown","location"]},"line_id":{"$ref":"#/components/schemas/NullableId"},"counted_quantity":{"$ref":"#/components/schemas/NullableQuantity"},"message":{"type":["string","null"]},"transaction_id":{"$ref":"#/components/schemas/NullableId"},"changed":{"type":"boolean"},"approval_status":{"const":"pending"},"adjustment_request_id":{"type":"integer"},"reference":{"type":"string"}}}}},"WebhookEvent":{"type":"object","description":"Every delivery is a POST with this body and two headers. `X-Webhook-Id` repeats `id`: use it to ignore\nduplicates. `X-Webhook-Signature` is `t=<unix time>,v1=<hex>`, where the hex is the HMAC-SHA256 of\n`\"<t>.<raw body>\"` with the endpoint's secret. Reject a delivery whose `t` is more than 5 minutes from now, or\nwhose `v1` doesn't match (compare in constant time).\n","required":["id","type","created_at","organization","data"],"properties":{"id":{"type":"string","description":"evt_…, the same in every retry."},"type":{"type":"string"},"created_at":{"$ref":"#/components/schemas/Timestamp"},"organization":{"type":"string","description":"The organization's slug."},"data":{"type":"object"}}}}}}