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 is | Loading sales that have already happened | Evaluating a cart while the customer is at the till |
| When it runs | Batch, or once per closed ticket | Synchronously, during the sale |
| What you do with the response | Log it | Apply the returned effects to the cart the customer is paying for |
| Calls | POST /carts/realtime, or files | POST /carts/simulate, then POST /carts/realtime |
| Guide | This page | Checkout 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.
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.
| Level | Carries | Referential dependency |
|---|---|---|
| Header | Cart ID or code, customer identifier, location_id, date, total, payment method, country | The location must exist; the customer must exist unless the sale is unidentified |
| Lines | Product identifier, quantity, unit price, line total, and the header they belong to | Every 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β
| Situation | How it arrives |
|---|---|
| Partial return | A 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 cancellation | POST /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β
| Approach | Shape | When it fits |
|---|---|---|
| Files, daily | Header and line files dropped once or several times a day | Source systems that already export sales feeds; the usual starting point |
| API, per closed ticket | One POST /carts/realtime per completed sale | Where near-real-time loyalty state matters β the balance a customer sees is current |
| Real-time checkout | Simulate then confirm during the sale | When 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β
| Action | Endpoint |
|---|---|
| Create a cart | POST /carts/realtime |
| Simulate a cart without persisting | POST /carts/simulate |
| Get a cart | GET /carts/{id} |
| List carts | GET /carts |
| Cancel a cart in full | POST /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β
| Symptom | What to check |
|---|---|
| Cart accepted but the customer got no points | Whether the cart was a silent duplicate β same cart ID, same line order as an existing one. |
| Historical carts loaded but segments are empty | The load completed, and the tickets reference customers, products and locations that exist. |
| Totals in Loyal Guru do not match the source system | Header total vs sum of lines; the endpoint does not reject incoherent carts. |
| Return was rejected | Quantity greater than the original line quantity, or a cart that was already cancelled. |
| Vouchers not rolled back after cancellation | Whether the cancellation ran less than 5 minutes after the original cart. |
| Points appear late | File frequency. A daily load means a full day of delay between the purchase and the balance. |