Skip to main content

Carts

A cart β€” an activity in the API, a ticket on the shop floor β€” is a purchase event: a header with the customer, store, date and totals, and a set of lines with the products, quantities and amounts.

Carts are the entity that makes the loyalty program mean anything. Points, tiers, RFM segments, historical audiences and discount reporting are all derived from them. It is also the only entity in the data connection with a real historical dimension: the initial load brings the last 24 months of tickets, which is what allows segmentation and tier calculation to work from day one instead of after a year of accumulation.

This is not the checkout flow​

The same endpoint appears in two different connections, and confusing them is the most common design error in this part of the integration.

Carts as data (this page)Checkout integration
What it isLoading sales that have already happenedEvaluating a cart while the customer is at the till
When it runsBatch, or once per closed ticketSynchronously, during the sale
What you do with the responseLog itApply the returned effects to the cart the customer is paying for
CallsPOST /carts/realtime, or filesPOST /carts/simulate, then POST /carts/realtime
GuideThis pageCheckout integration

The distinction is the purpose of the call, not the technology. POST /carts/realtime is a commit in both cases: it persists the transaction, and depending on the Company configuration it awards points and consumes vouchers. That is exactly what you want during a sale. Whether you want it for a batch of sales that already closed hours ago is a decision to make explicitly.

caution

Decide how historical and batch loads are treated

Confirm with the Loyal Guru project team how loyalty effects should be handled for carts that are not being evaluated live β€” historical tickets, and any batch synchronisation of already-closed sales. Amounts in those carts were calculated by the source system, not by Loyal Guru, and whether points, vouchers and campaign effects should be applied, recalculated or skipped is a per-project decision that belongs in the design, not in a retry. The apply_discounts flag and the historical load path both depend on that answer.

Header and lines​

Two files, one payload. In the file world, ticket headers and ticket lines are separate CSVs loaded together and joined on the ticket identifier. Over the API, they are a single cart object with a lines array.

LevelCarriesReferential dependency
HeaderCart ID or code, customer identifier, location_id, date, total, payment method, countryThe location must exist; the customer must exist unless the sale is unidentified
LinesProduct identifier, quantity, unit price, line total, and the header they belong toEvery product must exist in the catalogue

Field-level definitions for the file layout are in the Data Tracks template; the API payload shape is in Checkout integration β†’ Step 5 and the cart endpoints reference.

Data integrity is on your side​

POST /carts/realtime does not validate cart integrity or coherence. This is documented behaviour, and it has two consequences worth designing around:

  • Duplicates are silent. If you resend a cart that is not unique β€” same cart ID, same order in every line β€” the endpoint responds as if it had succeeded, but the effects behind it are not applied: no points awarded, no vouchers redeemed. A duplicate does not double-count, but your system cannot tell a real confirmation from a swallowed duplicate either.
  • Incoherent data is accepted. If the header total does not equal the sum of the lines, or the customer identifier does not exist, the cart is processed anyway and the customer still gets their points.

So the checks belong in your pipeline, before the load. The seven pre-send checks in Data β†’ Before you send the first load exist for exactly this reason β€” three of them are about cart referential integrity, and one about returns carrying negative values.

Cart IDs that are unique, generated once at the origin of the sale and reused on every retry, are what keep the behaviour predictable. Retry semantics and the ambiguous-timeout case: Reliability.

Returns and cancellations​

SituationHow it arrives
Partial returnA cart (or lines within one) with negative quantities and totals. Lines are only accepted for return when the quantity is less than or equal to the original line quantity.
Full cancellationPOST /carts/cancellation, which creates a mirror return cart with negative amounts and triggers the rollback of points, vouchers and limits. The original cart is not modified.

Two constraints on cancellation, both documented in the endpoint reference: wait at least 5 minutes after the original cart was created, so the asynchronous points and voucher processes have completed and can be rolled back correctly; and a ticket cannot be cancelled more than once, partially or completely.

Frequency​

ApproachShapeWhen it fits
Files, dailyHeader and line files dropped once or several times a daySource systems that already export sales feeds; the usual starting point
API, per closed ticketOne POST /carts/realtime per completed saleWhere near-real-time loyalty state matters β€” the balance a customer sees is current
Real-time checkoutSimulate then confirm during the saleWhen the customer should see benefits applied at the till β€” that is Checkout integration, not a data load

Moving from daily files to one API call per closed ticket is a common evolution once a program is live: it removes the delay between a purchase and the points appearing, at the cost of the POS or its middleware having to handle failures per transaction rather than per file.

Core endpoints​

ActionEndpoint
Create a cartPOST /carts/realtime
Simulate a cart without persistingPOST /carts/simulate
Get a cartGET /carts/{id}
List cartsGET /carts
Cancel a cart in fullPOST /carts/cancellation

GET /carts filters by customer, location, order and date range, with mutually exclusive combinations β€” check the reference before building a reconciliation job on it. For bulk analytical reads, use BI and Data Lake rather than paginating the API.

Markdown endpoint catalog: Carts Β· HTTP API

Checklist​

  • Cart IDs are unique per business transaction and generated at the origin of the sale.
  • Line totals add up to the header total.
  • Every line references a product that exists in the catalogue; every header references a location that exists.
  • Returns carry negative quantities and totals.
  • Unidentified sales carry an empty customer identifier, not a placeholder.
  • The historical load ran after the catalogue, locations and customers it references.
  • Treatment of loyalty effects for historical and batch carts is agreed and documented.

Troubleshooting​

SymptomWhat to check
Cart accepted but the customer got no pointsWhether the cart was a silent duplicate β€” same cart ID, same line order as an existing one.
Historical carts loaded but segments are emptyThe load completed, and the tickets reference customers, products and locations that exist.
Totals in Loyal Guru do not match the source systemHeader total vs sum of lines; the endpoint does not reject incoherent carts.
Return was rejectedQuantity greater than the original line quantity, or a cart that was already cancelled.
Vouchers not rolled back after cancellationWhether the cancellation ran less than 5 minutes after the original cart.
Points appear lateFile frequency. A daily load means a full day of delay between the purchase and the balance.