Order history
Bring read-only commercial order history dated before your organization's GL start date into ShelfCycle, without creating ledger transactions.
Use API v1.65 to import and maintain historical sales orders, stock purchase orders, and direct ship pairs. Preserve customer and supplier relationship history, margins, costs, prices, and volumes alongside the records your team uses today.
The saved documents are completed and read-only in everyday order workflows. This dedicated history route can add and correct their commercial details. It creates no ledger transactions and never creates or changes invoices, bills, shipments, or lots.
Dates and access
The organization's GL start date is its configured accounting cutover date. New sales orders need header.orderedAt; standalone purchase orders need header.submittedAt. The API checks that date strictly before the start day in the organization's timezone. A direct ship pair is checked using the sale's orderedAt; preserve the source purchase dates with the paired document. The start date and timezone must be configured before importing. History can be loaded or corrected after go-live; the dates of the imported orders belong to the earlier period.
Use order-history:write and the acting person's current Sales Order or Purchase Order update access for each document involved. Creating history also requires the corresponding create permission. Each document must be visible to that person. Full-access keys include the scope. GET /me reports effectiveCapabilities.orderHistory.write as an overall readiness hint; preview checks the permissions needed by each item. Changing cost fields also needs current cost viewing access.
Read sales orders with orders:read, and purchase orders with purchase-orders:read. Invoice details additionally require invoices:read; bill details require bills:read and cost viewing access, together with the corresponding current document permissions.
Find and review history
Use history=true on GET /orders or GET /purchase-orders alongside an exact identifier or another supported narrowing filter. history=false selects ordinary orders. Sales order lists also accept issue with a supported quality flag and a business-date window of at most 366 days. Continue using meta.nextCursor with the original filters and page size.
curl "$SHELFCYCLE_API_BASE_URL/orders?history=true&fromDate=2025-01-01&toDate=2025-12-31&limit=25" \
-H "Authorization: Bearer $SHELFCYCLE_API_KEY"
Read GET /orders/{id} or GET /purchase-orders/{id} for the selected record. Responses include history, terms, pickup and shipment context, and available cost, margin, invoice, bill, and quality information. Keep the returned updatedAt and exact timestamps for corrections. Amounts and cost details follow the key's scopes and the acting person's permissions.
Prepare an import
Send POST /order-history/batch with 1–10 independent items and a body up to 2 MiB. Each item has a unique clientItemId and a payload containing action, kind, and the relevant documents. Use sales_order, purchase_order, or direct_ship_pair for kind. A pair carries both salesOrder and purchaseOrder; the other kinds carry just their named document.
For action: "create", each document needs a stable externalId, header.orderNo, the appropriate pre-start date, and the customer or supplier and line details required by that document. Resolve customer, supplier, product, and packaging IDs in your organization first. History is saved in the organization's base currency, as completed read-only documents with no warehouse. Reusing an imported externalId returns the existing history document unchanged; use update for corrections.
For a direct ship pair, give sale lines a clientLineId and reference them from purchase lines with salesOrderLineRef. A linked sale line's cost comes from the contributing purchase lines, including tied landed costs. Put unitCostCents on those purchase lines.
Money is sent as strings in cents. Unit prices and unit costs can contain fractional cents. Quantities are decimal strings. Send dates as ISO timestamps with an offset.
Preview a correction
Use action: "update", identify each document by id or externalId, and send expectedUpdatedAt equal to the updatedAt from its latest read. This route uses that body field for concurrency checks.
The example previews a customer order number correction. Replace the sample ID and timestamp with values from the selected history record.
curl "$SHELFCYCLE_API_BASE_URL/order-history/batch?dryRun=true" \
-X POST \
-H "Authorization: Bearer $SHELFCYCLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"items": [
{
"clientItemId": "history-sale-1042",
"payload": {
"action": "update",
"kind": "sales_order",
"salesOrder": {
"id": "5cd5a0b3-0821-4b1a-8b03-c0618e34c40e",
"expectedUpdatedAt": "2026-11-17T14:00:00.000Z",
"header": { "customerOrderNo": "CUSTOMER-1042" }
}
}
}
]
}'
Header fields patch the selected document. Lines and costs patch by row ID. A row with id changes that row; a row without id adds one. To remove a row, send only its id and remove: true. Omitted rows stay as they were. Send a document only once in a batch.
Preview saves nothing. Review each item's before, after, changes, and totals, as well as the batch totals. Totals derive from the document's lines and costs on every write, and margins refresh when the documents are saved. The preview supplies no plan token; submit exactly the reviewed intent when applying it.
Apply and verify
Remove dryRun=true, keep the reviewed body, and supply a stable Idempotency-Key. Each item saves independently. Check every item's result before proceeding. Retry an interrupted batch with the identical key and body to resume pending items. Reusing a key with a changed body returns 409.
Read the saved documents again to confirm their commercial details, totals, margins, and timestamps. An invoice can retain different recorded revenue after an order correction; revenue_differs_from_invoice identifies that difference. The history route reads the invoice and leaves it intact.
Review returned guidance
stale_record means the document changed after your read. Read it again and review a fresh preview. date_not_before_go_live and go_live_date_required identify date setup issues on new imports.
The route accepts read-only history documents in base currency. Documents linked to ledger transactions or live records are refused. Row removal and changes also respect existing invoice, bill, receipt, and lot links. A revenue change with a percentage cost already on a bill returns percentage_cost_on_bill; changing billed costs can return cost_on_bill. Keep the returned item guidance with your import results and resolve it before retrying.
See Finders, Financial records, and the endpoint reference for the complete request fields and readable order context.