Skip to main content

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.

EndpointPermission
POST /api/v1/stock-ordersdevice_stock:create
GET /api/v1/stock-ordersdevice_stock:read
GET /api/v1/stock-orders/:iddevice_stock:read
POST /api/v1/stock-orders/:id/linesdevice_stock:create
DELETE /api/v1/stock-orders/:id/lines/:lineIddevice_stock:create
POST /api/v1/stock-orders/:id/confirmdevice_stock:update
POST /api/v1/stock-orders/:id/canceldevice_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)
StateMeaningWhat you can do
DRAFTDraft. Does not touch stock.Add and remove lines, confirm, cancel.
CONFIRMEDWhat was really done was declared and applied to stock at once. It is the only step that moves stock.Nothing: it is final.
CANCELLEDAbandoned draft. Moved nothing.Nothing: it is final.
  • CONFIRMED and CANCELLED are final: the document is never rewritten. Correcting a load is another order in the opposite direction.
  • Any write on an order that is not DRAFT returns 409 stock_orders.not_editable.
  • There is no delete: a draft you will not use is cancelled.

Rules​

  • Only devices restocked by filling trays: types SPRING and BELT. The rest (LOCKER is restocked through its own loads, LIQUID/COFFEE/ICE_CREAM are refilled with supplies, RETURN receives no goods) return 400 stock_orders.not_applicable on 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) requires reason.
  • 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 with qty: 0 moves 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 returns 409 stock_orders.qty_not_applicable. Fix the declaration and confirm again.
  • Every applied line leaves a LOAD/UNLOAD movement with source: "STOCK_ORDER" and its stockOrder in the selection movements, and updates currentQty in 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"
}
FieldTypeDescription
iduuid
numberintegerSequential number within the account.
deviceobject | nullDevice: { id, serial, name }. null if the order has no device that can be resolved; a deleted device still arrives with its current name.
operationobject | nullThe device's operation when the order was opened: { id, name }.
statusenumDRAFT, CONFIRMED, CANCELLED.
notestring | nullFree note.
lines[].iduuidLine id (to remove it).
lines[].selectionstringSelection.
lines[].kindenumPlanned direction: LOAD (adds) or UNLOAD (subtracts).
lines[].qtyPlannedintegerPlanned units (0 = selection moved outside the plan).
lines[].actualKindenum | nullReal direction. null until confirmed.
lines[].qtyActualinteger | nullReal units. null until confirmed.
lines[].varianceinteger | nullReal − planned, signed relative to the selection.
lines[].productobject | nullThe selection's product when the line was built: { id, sku, name }. sku is always null: the line does not store the SKU.
lines[].reasonenum | nullEXPIRED, DAMAGED, ROTATION, PRODUCT_CHANGE, RECOUNT, OTHER.
lines[].qtyBefore / qtyAfterinteger | nullStock when applied. null until confirmed.
lines[].slotCapacityinteger | nullSelection capacity when applied.
lines[].capacityShortfallintegerPart of the difference the selection could not hold (not a shortage).
lines[].missingintegerPart of the difference that fit and did not arrive.
totalLoaded / totalUnloadedintegerPlanned totals.
actualLoaded / actualUnloadedinteger | nullReal totals; null until confirmed.
discrepancyCountintegerLines that did not go as planned.
totalCapacityShortfall / totalMissingintegerLine sums.
confirmedAt / cancelledAtISO 8601 | null
createdAt / updatedAtISO 8601 UTC

Create an order​

POST /api/v1/stock-orders

Permission: device_stock:create. Opens an empty DRAFT order. Does not touch stock.

FieldTypeRequiredLimitsEditable later
deviceIdstringyesA device of the account, type SPRING or BELT: its id or its serial.no
notestring | nullnoMax 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.

QueryTypeRequiredDefaultLimits / values
pageintegerno1≥ 1
pageSizeintegerno501–200
sortByenumnocreatedAtcreatedAt (only value)
sortOrderenumnodescasc, desc
deviceIdstringno—Orders for that device: its id or its serial. If it does not exist in the account → empty page.
statusenumno— (all)DRAFT, CONFIRMED, CANCELLED (lowercase accepted).
fromISO 8601no—createdAt ≥ from (inclusive).
toISO 8601no—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 paramTypeDescription
iduuidOrder 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 paramTypeDescription
iduuidOrder id.
FieldTypeRequiredLimits / values
selectionstringyesMax 16. Must exist in the planogram ("07" = "7"). One line per selection.
kindenumyesLOAD, UNLOAD (lowercase accepted).
qtyintegeryes1 – 2147483647.
reasonenumif kind is UNLOADEXPIRED, 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 paramTypeDescription
iduuidOrder id.
lineIduuidLine 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 paramTypeDescription
iduuidOrder id.
FieldTypeRequiredLimits / values
linesarraynoMax 500. Omitted = the plan was done as is. Sent = complete declaration (see rules).
lines[].selectionstringyesMax 16.
lines[].kindenumyesLOAD, UNLOAD: what really happened, may differ from the plan.
lines[].qtyintegeryes0 – 2147483647 (0 = not touched).
lines[].reasonenumif kind is UNLOAD and qty is greater than 0Same 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​

HTTPcodeWhen
400stock_orders.not_applicableCreating on a device that is not SPRING or BELT.
400stock_orders.invalid_lineUNLOAD 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.
400devices.planogram_not_applicableThe device has no planogram (when adding or declaring a selection).
401http.unauthorizedThe key is missing, invalid, revoked or expired.
403http.forbiddenThe key lacks the endpoint's permission.
404stock_orders.not_foundThe order does not exist, belongs to another account or the id is not a uuid.
404devices.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.
404devices.slot_not_foundThe selection does not exist in the planogram.
409stock_orders.not_editableAdding or removing lines, confirming or cancelling an order that is not DRAFT.
409stock_orders.qty_not_applicableOn confirm, a line removes more than there is or exceeds capacity: no line is applied.
422validation.failedInvalid body or query: enum out of range, qty below 1 in a plan line, wrong types, fields not allowed (e.g. productId).
429http.too_many_requestsThe key's rate limit was exceeded.