API: stock orders
General conventions in How the API works.
The stock order is the only way to change inventory through the API: there are no direct writes
of planograms, selections or loads. It is the document of a visit to the machine: what was planned
and what was really moved. It uses the same state machine as the app (Stock
orders). An order, or a device when creating one, from another account
returns 404.
| Endpoint | Permission |
|---|---|
POST /api/v1/stock-orders | device_stock:create |
GET /api/v1/stock-orders | device_stock:read |
GET /api/v1/stock-orders/:id | device_stock:read |
POST /api/v1/stock-orders/:id/lines | device_stock:create |
DELETE /api/v1/stock-orders/:id/lines/:lineId | device_stock:create |
POST /api/v1/stock-orders/:id/confirm | device_stock:update |
POST /api/v1/stock-orders/:id/cancel | device_stock:update |
The order and its lines have no natural key: :id and :lineId are ids. The device is given by id
or serial (see References).
State machine
POST /stock-orders
│
▼
DRAFT ── POST /:id/lines, DELETE /:id/lines/:lineId (build the plan)
│
POST /:id/confirm POST /:id/cancel
▼ ▼
CONFIRMED CANCELLED
(applied to stock) (moves nothing)
| State | Meaning | What you can do |
|---|---|---|
DRAFT | Draft. Does not touch stock. | Add and remove lines, confirm, cancel. |
CONFIRMED | What was really done was declared and applied to stock at once. It is the only step that moves stock. | Nothing: it is final. |
CANCELLED | Abandoned draft. Moved nothing. | Nothing: it is final. |
CONFIRMEDandCANCELLEDare final: the document is never rewritten. Correcting a load is another order in the opposite direction.- Any write on an order that is not
DRAFTreturns409 stock_orders.not_editable. - There is no delete: a draft you will not use is cancelled.
Rules
- Only devices restocked by filling trays: types
SPRINGandBELT. The rest (LOCKERis restocked through its own loads,LIQUID/COFFEE/ICE_CREAMare refilled with supplies,RETURNreceives no goods) return400 stock_orders.not_applicableon create. - One line per selection, and the selection must exist in the device's planogram.
- The server sets the product: it is taken from the selection (not sent). An order cannot claim that something was loaded that the machine did not have set.
- The planned quantity is greater than 0. A removal (
UNLOAD) requiresreason. - Confirming with no body = exactly the plan was done. Confirming with
lines= a complete declaration of what really happened: plan selections not included become 0 (not done) and selections outside the plan are accepted (recorded with plan 0). A selection declared withqty: 0moves nothing. - Confirming requires at least one line and something to move: all zeros is a cancellation and
returns
400 stock_orders.invalid_line. - All or nothing: everything is validated before applying. If a line removes more than there is,
or loads above capacity (
maxQty), no line is applied and the API returns409 stock_orders.qty_not_applicable. Fix the declaration and confirm again. - Every applied line leaves a
LOAD/UNLOADmovement withsource: "STOCK_ORDER"and itsstockOrderin the selection movements, and updatescurrentQtyin the planogram.
The order
{
"id": "01a12147-f059-7342-93b9-c5b051226b3f",
"number": 5,
"device": { "id": "00000000-0000-7000-8000-0000000000d2", "serial": "UN20W103447", "name": "Vending Corferias 2" },
"operation": { "id": "00000000-0000-7000-8000-0000000000a2", "name": "TEST INGENIERÍA" },
"status": "CONFIRMED",
"note": "North route",
"lines": [
{
"id": "01a12147-f065-712c-952d-c99d7dbce2f9",
"selection": "10",
"kind": "LOAD",
"qtyPlanned": 1,
"actualKind": "LOAD",
"qtyActual": 1,
"variance": 0,
"product": { "id": "00000000-0000-7000-8000-0000000000b4", "sku": null, "name": "Gafas de seguridad" },
"reason": null,
"qtyBefore": 19,
"qtyAfter": 20,
"slotCapacity": 20,
"capacityShortfall": 0,
"missing": 0
}
],
"totalLoaded": 1,
"totalUnloaded": 0,
"actualLoaded": 1,
"actualUnloaded": 0,
"discrepancyCount": 0,
"totalCapacityShortfall": 0,
"totalMissing": 0,
"confirmedAt": "2026-10-09T15:28:45.179Z",
"cancelledAt": null,
"createdAt": "2026-10-09T15:28:45.149Z",
"updatedAt": "2026-10-09T15:28:45.179Z"
}
| Field | Type | Description |
|---|---|---|
id | uuid | |
number | integer | Sequential number within the account. |
device | object | null | Device: { id, serial, name }. null if the order has no device that can be resolved; a deleted device still arrives with its current name. |
operation | object | null | The device's operation when the order was opened: { id, name }. |
status | enum | DRAFT, CONFIRMED, CANCELLED. |
note | string | null | Free note. |
lines[].id | uuid | Line id (to remove it). |
lines[].selection | string | Selection. |
lines[].kind | enum | Planned direction: LOAD (adds) or UNLOAD (subtracts). |
lines[].qtyPlanned | integer | Planned units (0 = selection moved outside the plan). |
lines[].actualKind | enum | null | Real direction. null until confirmed. |
lines[].qtyActual | integer | null | Real units. null until confirmed. |
lines[].variance | integer | null | Real − planned, signed relative to the selection. |
lines[].product | object | null | The selection's product when the line was built: { id, sku, name }. sku is always null: the line does not store the SKU. |
lines[].reason | enum | null | EXPIRED, DAMAGED, ROTATION, PRODUCT_CHANGE, RECOUNT, OTHER. |
lines[].qtyBefore / qtyAfter | integer | null | Stock when applied. null until confirmed. |
lines[].slotCapacity | integer | null | Selection capacity when applied. |
lines[].capacityShortfall | integer | Part of the difference the selection could not hold (not a shortage). |
lines[].missing | integer | Part of the difference that fit and did not arrive. |
totalLoaded / totalUnloaded | integer | Planned totals. |
actualLoaded / actualUnloaded | integer | null | Real totals; null until confirmed. |
discrepancyCount | integer | Lines that did not go as planned. |
totalCapacityShortfall / totalMissing | integer | Line sums. |
confirmedAt / cancelledAt | ISO 8601 | null | |
createdAt / updatedAt | ISO 8601 UTC |
Create an order
POST /api/v1/stock-orders
Permission: device_stock:create. Opens an empty DRAFT order. Does not touch stock.
| Field | Type | Required | Limits | Editable later |
|---|---|---|---|---|
deviceId | string | yes | A device of the account, type SPRING or BELT: its id or its serial. | no |
note | string | null | no | Max 500. | no |
curl -X POST https://back.inssacs.com/api/v1/stock-orders \
-H 'x-api-key: ics_a1b2c3d4_e5f6...' \
-H 'Content-Type: application/json' \
-d '{ "deviceId": "ICS595DDE99B", "note": "North route" }'
Response 201: the order with status: "DRAFT" and lines: [] (as in the list example).
List orders
GET /api/v1/stock-orders
Permission: device_stock:read.
| Query | Type | Required | Default | Limits / values |
|---|---|---|---|---|
page | integer | no | 1 | ≥ 1 |
pageSize | integer | no | 50 | 1–200 |
sortBy | enum | no | createdAt | createdAt (only value) |
sortOrder | enum | no | desc | asc, desc |
deviceId | string | no | — | Orders for that device: its id or its serial. If it does not exist in the account → empty page. |
status | enum | no | — (all) | DRAFT, CONFIRMED, CANCELLED (lowercase accepted). |
from | ISO 8601 | no | — | createdAt ≥ from (inclusive). |
to | ISO 8601 | no | — | createdAt before to (exclusive). |
Example
curl 'https://back.inssacs.com/api/v1/stock-orders?status=DRAFT&deviceId=ICS595DDE99B' \
-H 'x-api-key: ics_a1b2c3d4_e5f6...'
Response 200
{
"data": [
{
"id": "01a12147-f059-7342-93b9-c5b051226b3f",
"number": 6,
"device": { "id": "00000000-0000-7000-8000-0000000000d2", "serial": "UN20W103447", "name": "Vending Corferias 2" },
"operation": { "id": "00000000-0000-7000-8000-0000000000a2", "name": "TEST INGENIERÍA" },
"status": "DRAFT",
"note": "North route",
"lines": [],
"totalLoaded": 0,
"totalUnloaded": 0,
"actualLoaded": null,
"actualUnloaded": null,
"discrepancyCount": 0,
"totalCapacityShortfall": 0,
"totalMissing": 0,
"confirmedAt": null,
"cancelledAt": null,
"createdAt": "2026-10-09T15:20:02.511Z",
"updatedAt": "2026-10-09T15:20:02.511Z"
}
],
"pagination": { "page": 1, "pageSize": 50, "total": 1 }
}
Get an order
GET /api/v1/stock-orders/:id
Permission: device_stock:read.
| Path param | Type | Description |
|---|---|---|
id | uuid | Order id. |
Response 200: the order.
Add a line
POST /api/v1/stock-orders/:id/lines
Permission: device_stock:create. Only in DRAFT. Adds a selection to the plan.
| Path param | Type | Description |
|---|---|---|
id | uuid | Order id. |
| Field | Type | Required | Limits / values |
|---|---|---|---|
selection | string | yes | Max 16. Must exist in the planogram ("07" = "7"). One line per selection. |
kind | enum | yes | LOAD, UNLOAD (lowercase accepted). |
qty | integer | yes | 1 – 2147483647. |
reason | enum | if kind is UNLOAD | EXPIRED, DAMAGED, ROTATION, PRODUCT_CHANGE, RECOUNT, OTHER. |
productId is not sent: the server takes it from the selection (sending it → 422). A line is not
edited: remove it and add it again.
{ "selection": "10", "kind": "LOAD", "qty": 5 }
Response 201: the full order with the new line:
{
"id": "01a12147-f059-7342-93b9-c5b051226b3f",
"number": 6,
"device": { "id": "00000000-0000-7000-8000-0000000000d2", "serial": "UN20W103447", "name": "Vending Corferias 2" },
"operation": { "id": "00000000-0000-7000-8000-0000000000a2", "name": "TEST INGENIERÍA" },
"status": "DRAFT",
"note": "North route",
"lines": [
{
"id": "01a12147-f065-712c-952d-c99d7dbce2f9",
"selection": "10",
"kind": "LOAD",
"qtyPlanned": 5,
"actualKind": null,
"qtyActual": null,
"variance": null,
"product": { "id": "00000000-0000-7000-8000-0000000000b4", "sku": null, "name": "Gafas de seguridad" },
"reason": null,
"qtyBefore": null,
"qtyAfter": null,
"slotCapacity": null,
"capacityShortfall": 0,
"missing": 0
}
],
"totalLoaded": 5,
"totalUnloaded": 0,
"actualLoaded": null,
"actualUnloaded": null,
"discrepancyCount": 0,
"totalCapacityShortfall": 0,
"totalMissing": 0,
"confirmedAt": null,
"cancelledAt": null,
"createdAt": "2026-10-09T15:20:02.511Z",
"updatedAt": "2026-10-09T15:21:40.002Z"
}
Remove a line
DELETE /api/v1/stock-orders/:id/lines/:lineId
Permission: device_stock:create. Only in DRAFT.
| Path param | Type | Description |
|---|---|---|
id | uuid | Order id. |
lineId | uuid | Line id (lines[].id). |
Response 204 with no body. A lineId that is not in the order does nothing and also returns 204.
Confirm an order
POST /api/v1/stock-orders/:id/confirm
Permission: device_stock:update. Declares what was really done, applies it to stock and closes
the order (CONFIRMED).
| Path param | Type | Description |
|---|---|---|
id | uuid | Order id. |
| Field | Type | Required | Limits / values |
|---|---|---|---|
lines | array | no | Max 500. Omitted = the plan was done as is. Sent = complete declaration (see rules). |
lines[].selection | string | yes | Max 16. |
lines[].kind | enum | yes | LOAD, UNLOAD: what really happened, may differ from the plan. |
lines[].qty | integer | yes | 0 – 2147483647 (0 = not touched). |
lines[].reason | enum | if kind is UNLOAD and qty is greater than 0 | Same as in lines. |
Confirm the plan as is (no body):
curl -X POST https://back.inssacs.com/api/v1/stock-orders/01a12147-f059-7342-93b9-c5b051226b3f/confirm \
-H 'x-api-key: ics_a1b2c3d4_e5f6...'
Declare what really happened (selection 10 only took 4 of 5; selection 12, not in the plan, had 2 expired units removed):
{
"lines": [
{ "selection": "10", "kind": "LOAD", "qty": 4 },
{ "selection": "12", "kind": "UNLOAD", "qty": 2, "reason": "EXPIRED" }
]
}
Response 200: the confirmed order, with qtyBefore/qtyAfter per line (see
the order).
Cancel an order
POST /api/v1/stock-orders/:id/cancel
Permission: device_stock:update. No body. Abandons a draft (CANCELLED); moves nothing.
Response 200: the order with status: "CANCELLED" and cancelledAt set.
Errors
| HTTP | code | When |
|---|---|---|
| 400 | stock_orders.not_applicable | Creating on a device that is not SPRING or BELT. |
| 400 | stock_orders.invalid_line | UNLOAD with no reason; selection repeated in the order or in the declaration; declared selection that cannot be added; confirming with no lines or nothing to move. |
| 400 | devices.planogram_not_applicable | The device has no planogram (when adding or declaring a selection). |
| 401 | http.unauthorized | The key is missing, invalid, revoked or expired. |
| 403 | http.forbidden | The key lacks the endpoint's permission. |
| 404 | stock_orders.not_found | The order does not exist, belongs to another account or the id is not a uuid. |
| 404 | devices.not_found | (Create) No device with that id or serial in the account. (Add or remove lines, confirm, cancel) The order's device was deleted after the order was opened. |
| 404 | devices.slot_not_found | The selection does not exist in the planogram. |
| 409 | stock_orders.not_editable | Adding or removing lines, confirming or cancelling an order that is not DRAFT. |
| 409 | stock_orders.qty_not_applicable | On confirm, a line removes more than there is or exceeds capacity: no line is applied. |
| 422 | validation.failed | Invalid body or query: enum out of range, qty below 1 in a plan line, wrong types, fields not allowed (e.g. productId). |
| 429 | http.too_many_requests | The key's rate limit was exceeded. |