Orders

The customer's order surface: list, detail (items with their totals, fulfillments with tracking, addresses, the money, the delivery method, the pickup point and the tender) and order transfers. There is no anonymous order read by id or number: every endpoint on this page is for a signed-in customer (the store's session cookie from the code sign-in, see auth.md, or a customer bearer token), with ONE exception. An order has a public page, {store}/order/{key}, and the read behind it opens with the order's key alone: the key is minted with the order, reaches the storefront in the completeCart() response (order.access_key, checkout.md), rides every order email's link and every row of the account's order list, and it is the whole credential, so a number or an id alone opens nothing. Nobody signed in on the customer's reads answers 401 {code: "unauthenticated"}, demonstrated executably below; a wrong key answers 404 not_found, like a missing order. Happy-path shapes are shown as jsonc: they need a signed-in session, or the order's key.

Auth for every endpoint on this page: x-client-id + a signed-in customer, except the read by key.

SDK module: @cartbase/storefront/api/orders.


GET /api/store/orders/key/:key: the order's page

  • Purpose: the order as it stands, for whoever holds its key: the page the checkout lands on, the page every order email links, a bookmark of it, on any device, today and later. It answers with the full detail (the shape under GET /api/store/orders/:id below). One page for every order: its heading follows status, payment_status and fulfillment_status, and its money follows the order emails' rule, the total being what the order cost (a canceled order keeps it) with what was paid, refunded and still owed beneath it.
  • Auth: the key, 32 hex characters minted with the order. No session: this is the order's public page, for a guest as for an account holder. A wrong key is 404 not_found, indistinguishable from a missing order. Numbers and ids are guessable, which is exactly why neither opens an order to a guest and why the key is the address.
  • Request: GET, no query.
  • Response: identical {order} detail shape to GET /api/store/orders/:id below.
  • Errors: 404 not_found.
  • SDK: orders.retrieveOrderByKey(client, key); orders.orderPagePath(order) composes the page's address from a completion response.
  • Components: the order page (OrderCompletedTemplate), the checkout's orderConfirmedPath (/order/{key}), the merchant's View on the order in the admin.
  • Settings: none; the key is the database's.
STATUS=$(curl -s -o /dev/null -w '%{http_code}'   "$BASE/api/store/orders/key/00000000000000000000000000000000" -H "x-client-id: $CLIENT_ID")
test "$STATUS" = 404

GET /api/store/orders/display/:displayId: my order by its human number

  • Purpose: resolve "order #42" (the number customers see in emails and confirmations) to the full order detail; account order pages and support links use this instead of the opaque id.
  • Auth: a signed-in customer, same ownership scope as the id read: another customer's number is 404 not_found. display_id is a guessable autoincrement, that is exactly why there is no anonymous lookup by it; the order's public page opens by its key (above).
  • Request: GET, no query. A numeric segment matches the autoincrement display_id OR a purely-numeric custom_display_id (custom wins ties, it is the number the store actually showed); any other segment matches custom_display_id only.
  • Response: identical {order} detail shape to GET /api/store/orders/:id below.
  • Errors: 401 unauthenticated; 404 not_found.
  • SDK: orders.retrieveOrderByDisplayId(client, displayId).
  • Components: account order detail, support links.
  • Settings: custom_display_id is set by merchants/imports (admin surface); absent it, only the autoincrement resolves.
STATUS=$(curl -s -o /dev/null -w '%{http_code}'   "$BASE/api/store/orders/display/42" -H "x-client-id: $CLIENT_ID")
test "$STATUS" = 401

GET /api/store/orders: list my orders

  • Purpose: the account "My orders" list, newest first. Each row is what the list shows, and its key opens the order's own page (orders.orderPagePath(row), /order/{key}): there is no second order page. The orders a guest placed with the email before the first sign-in are listed too; the sign-in made that guest the account.
  • Auth: a signed-in customer. Scoped to that customer AND the tenant: another customer's orders are invisible (not 403).
  • Request: GET ?limit=&offset=&status=, limit 1 to 200 (default 20), offset ≥ 0 (default 0), status exact-match filter (pending, completed, canceled, …).
  • Response: one row per order:
{
  "orders": [{
    "id": "order_…",
    "number": "1042",              // what the customer was shown: the store's own number, else display_id
    "display_id": 1042,
    "custom_display_id": null,
    "status": "pending",
    "created_at": "2026-07-20T…",
    "canceled_at": null,
    "currency_code": "eur",
    "access_key": "5f0c…",         // the order's page: /order/{access_key}
    "total": 94.8,                 // what the order cost, VAT included, the order page's total
    "payment_status": "paid",      // not_paid | partially_paid | paid | partially_refunded | refunded | canceled
    "fulfillment_status": "shipped", // not_fulfilled | partially_fulfilled | fulfilled | partially_shipped | shipped | partially_delivered | delivered
    "item_count": 3,               // every line's quantity summed
    "items": [                     // the first four lines, for the row's preview
      { "title": "Linen Shirt", "variant_title": "M", "thumbnail": "https://…", "quantity": 2 }
    ]
  }],
  "count": 1, "offset": 0, "limit": 20
}
  • Errors: 401 unauthenticated; 400 validation_failed (bad limit/offset).
  • SDK: orders.listOrders(client, {limit, offset, status}).
  • Components: the account's order list.
  • Settings: none (ownership is structural).
# Executable auth contract: nobody signed in, 401 unauthenticated.
STATUS=$(curl -s -o /dev/null -w '%{http_code}' \
  "$BASE/api/store/orders" -H "x-client-id: $CLIENT_ID")
test "$STATUS" = 401

GET /api/store/orders/:id: my order, in full

  • Purpose: the order-detail page: items with their totals, fulfillment lifecycle + tracking, both addresses, the money, the delivery method, the pickup point, the tender.
  • Auth: a signed-in customer. Ownership is part of the lookup: an unknown id and another customer's order are BOTH 404 not_found (indistinguishable, no existence oracle).
  • Request: GET, no query.
  • Response: a store-safe subset of the admin order select (no customer row, no payment internals, no internal timeline comments), decorated by the platform with what the order's page shows. Every amount is in the shopper's money, VAT included, the same figures the admin's Payment card shows:
{
  "order": {
    "id": "order_…", "display_id": 42, "custom_display_id": null,
    "status": "pending",             // "canceled" once canceled, with canceled_at
    "canceled_at": null,
    "payment_status": "not_paid",    // the account list's word: not_paid | partially_paid | paid | partially_refunded | refunded | canceled
    "fulfillment_status": "not_fulfilled", // not_fulfilled | partially_fulfilled | fulfilled | partially_shipped | shipped | partially_delivered | delivered
    "email": "jane@example.com", "currency_code": "eur",
    "totals": {
      "currency_code": "eur",
      "items_total": 45,             // the items before discounts, VAT included
      "discount_total": 0,           // every discount, VAT included
      "shipping_total": 5.72,        // the delivery method's price, VAT included
      "payment_method_fee_total": 1, // the method's fee when charged; inside total
      "payment_method_fee_label": "Такса наложен платеж",
      "tax_total": 8.62,             // the VAT inside the total
      "total": 51.72,                // what the order cost: the rows above added up; a canceled order keeps it
      "paid_total": 0,               // what came in
      "refunded_total": 0,           // what went back
      "balance_due": 51.72           // what is still owed; 0 once paid or canceled
    },
    "shipping_methods": [{ "id": "osm_…", "name": "До офис на Speedy", "shipping_option_id": "so_…", "amount": 5.72 }],
    "pickup_point": {               // null when the parcel goes to the address
      "provider": "speedy", "mode": "office", "id": "774",
      "name": "СОФИЯ - ВИТОША (БУЛ.)", "address": "гр. СОФИЯ бул. ВИТОША No 129",
      "city": "СОФИЯ", "postal": "", "phone": ""
    },
    "payment_methods": [{           // the store's own method by its name, or a processor by its kind
      "name": "Наложен платеж", "provider_id": null, "kind": "cod"
    }],                             // a card: {"name": null, "provider_id": "pp_stripe", "kind": "card"}
    "items": [{                       // version pivot + embedded line item
      "id": "oi_…", "order_id": "order_…", "quantity": 1,
      "total": 45, "original_total": 45,   // the line as paid, after its discounts, VAT included
      "line_item": {
        "id": "oli_…", "title": "M", "product_title": "Linen Shirt",
        "product_handle": "linen-shirt", "thumbnail": "https://…",
        "variant_id": "variant_…", "variant_sku": "LIN-SHIRT-M",
        "unit_price": 45, "metadata": null
      }
    }],
    "fulfillments": [{                // couriers surface
      "fulfillment": {
        "id": "ful_…",
        "packed_at": "2026-07-20T…", "shipped_at": null,
        "delivered_at": null, "canceled_at": null,
        "labels": [{ "tracking_number": "…", "tracking_url": "https://…" }]
      }
    }],
    "shipping_address": { "first_name": "Jane", "city": "Sofia", "…": "order_addresses row" },
    "billing_address":  { "…": "order_addresses row" }
  }
}
  • Errors: 401 unauthenticated; 404 not_found.
  • SDK: orders.retrieveOrder(client, orderId).
  • Components: order-detail page, tracking widget.
  • Settings: fulfillment/tracking data appears as the merchant packs and ships (admin fulfillment flow + carrier labels).
STATUS=$(curl -s -o /dev/null -w '%{http_code}' \
  "$BASE/api/store/orders/order_any" -H "x-client-id: $CLIENT_ID")
test "$STATUS" = 401

Order transfers: claim a (guest) order into my account

Flow: the claiming customer calls request on an order that is not theirs, then a one-time token is stored for the order's email holder (email dispatch pending server-side), then the claimer, whose account email must EQUAL the order's email, calls accept with the token. decline (the recipient rejects, token required) or cancel (the requester withdraws) end a pending transfer. One pending transfer per order, a duplicate request acknowledges with the same {transfer: {requested: true}} shape without creating another. The token never crosses this surface: it is email-delivered only.

POST /api/store/orders/:id/transfer/request

  • Request: {description?}.
  • Response: 200 {"order":{"id":"order_…","transfer":{"requested":true}}} (or the existing pending action object on a duplicate request).
  • Errors: 401 unauthenticated; 404 not_found; 400 already_owned (the order already belongs to the caller).
  • SDK: orders.requestOrderTransfer(client, orderId, {description}).

POST /api/store/orders/:id/transfer/accept

  • Request: {token} (≥16 chars, from the transfer email).
  • Response: 200 {order}, the full updated order row, now owned by the caller.
  • Errors: 401 unauthenticated; 404 not_found (order / no pending transfer); 403 invalid_token | email_mismatch (the caller's email must match the order's original email, a leaked token alone is not enough); 400 validation_failed.
  • SDK: orders.acceptOrderTransfer(client, orderId, {token}).

POST /api/store/orders/:id/transfer/decline

  • Request: {token}.
  • Response: 200 {"order":{"id":"order_…","transfer":{"declined":true}}}.
  • Errors: 401 unauthenticated; 404 not_found; 403 invalid_token; 400 validation_failed.
  • SDK: orders.declineOrderTransfer(client, orderId, {token}).

POST /api/store/orders/:id/transfer/cancel

  • Request: no body.
  • Response: 200 {"order":{"id":"order_…","transfer":{"canceled":true}}}.
  • Errors: 401 unauthenticated; 404 not_found; 403 forbidden (only the requester may cancel).
  • SDK: orders.cancelOrderTransfer(client, orderId).
  • Components: account "claim this order" flow + the transfer email's accept/decline landing page.
# Executable auth contract for the transfer family (all four for a signed-in customer).
# Note the ordering nuance: accept/decline validate the BODY before auth,
# so a missing token 400s even for guests; request/cancel hit auth first.
for EP in transfer/request transfer/cancel; do
  STATUS=$(curl -s -o /dev/null -w '%{http_code}' -X POST \
    "$BASE/api/store/orders/order_any/$EP" \
    -H "x-client-id: $CLIENT_ID" -H "content-type: application/json" -d '{}')
  test "$STATUS" = 401
done
for EP in transfer/accept transfer/decline; do
  RES=$(curl -s -X POST "$BASE/api/store/orders/order_any/$EP" \
    -H "x-client-id: $CLIENT_ID" -H "content-type: application/json" -d '{}')
  echo "$RES" | grep -q '"code":"validation_failed"'
  STATUS=$(curl -s -o /dev/null -w '%{http_code}' -X POST \
    "$BASE/api/store/orders/order_any/$EP" \
    -H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
    -d '{"token":"0123456789abcdef0123456789abcdef"}')
  test "$STATUS" = 401
done

Cleanup / accretion note

This page creates nothing, every executable block is a read/auth-contract probe against nonexistent ids.