# Record a sale

> Send the finished receipt so the member earns, and LoyX sees the sale.

Source: https://developers.loyx.se/guides/record-sale/

Send every finished receipt to LoyX, with or without a member. With a member, they earn. Without one, the sale still counts for the brand's reports, and the customer can claim it in the app later.

```
POST /v1/transactions
```

```json
{
  "transaction_type": "purchase",
  "currency": "SEK",
  "store_id": null,
  "member": [
    { "identifier": "membership_id", "value": "6f1c3e1a-0000-4000-8000-000000000001" }
  ],
  "external": {
    "external_transaction_id": "store12-reg3-000123",
    "external_store_id": "store12",
    "receipt_number": "000123",
    "purchased_at": "2026-11-20T10:15:00Z",
    "pos_system": "your-till-name",
    "cashier_id": "c-42"
  },
  "items": [
    {
      "sequence_number": 1,
      "external_product_id": "SKU-1001",
      "product_name": "Oat latte",
      "quantity": { "value": 2, "unit": "ea" },
      "unit_price": { "value": 4500, "currency": "SEK" },
      "tax_rate": 1200
    }
  ]
}
```

## The fields that matter

| Field | Why |
|---|---|
| `external.external_transaction_id` | **Your receipt id. Send it on every sale.** It is the duplicate key: a retry with the same id never books twice. It must be unique per brand for your system. If your receipt number is only unique per store or register, combine them, for example `store12-reg3-000123`. |
| `external.external_store_id` | Your own store code. LoyX maps it to the brand's store. You can send `store_id` (the LoyX UUID) instead. |
| `member` | Who bought. Use `membership_id` from [the lookup](/guides/identify-member/). Leave it empty for a guest. |
| `items` | One entry per receipt line, with `unit_price` and `quantity`. LoyX computes the totals. |
| `items[].external_product_id` | Your product id. LoyX uses it to match the line to the brand's catalog. |
| `external.purchased_at` | When the sale happened at the till, in UTC. |
| `items[].tax_rate` | VAT in hundredths of a percent: `2500` is 25 %, `1200` is 12 %. |

All amounts are [integers in minor units](/guides/money/).

## The response

`201 Created` with the stored transaction, including the totals LoyX computed and its `_id`. The `loyalty` block is empty at this point: **points are calculated after the sale**, usually within seconds. Read the [member card](/guides/member-card/) to see the new balance.

## Retries are safe

Network errors happen. If you did not get an answer, send the same request again with the same `external_transaction_id`.

| You send | You get |
|---|---|
| A new `external_transaction_id` | `201`, a new transaction. |
| The same id and the same content | `200` with the original transaction and the header `Idempotent-Replayed: true`. Nothing is booked twice. |
| The same id with different content | `409 external_transaction_id_conflict`. Two different receipts share one id: fix the id in your system. |

You may also send an `Idempotency-Key` header (a new UUID per sale). Reusing a key for a different sale is `409 idempotency_key_reused`. Details: [Idempotency](/guides/idempotency/).

## When the till only knows the total

Some systems only know what the customer paid. Send `totals` instead of `items`:

```json
{
  "currency": "SEK",
  "external": { "external_transaction_id": "web-88812" },
  "totals": { "paid_minor": 24900 }
}
```

`items` and `totals` cannot be sent together. Programs that earn on specific products cannot earn from a total, so send lines when you have them.

## Offline tills

Queue the sale locally and send it when the connection is back. Keep the same `external_transaction_id`. Late sales are accepted and count on the day they arrive.

## Discounts

Send the till's own discounts per line (`items[].discounts`) or per basket (`discounts`), each with a `type` (`sale`, `voucher`, `campaign`, `staff`, `manual`, `threshold`, `tier`) and an `amount` in minor units. Members earn on what they actually paid.

## Returns

Returns linked to the original receipt are coming. See [Returns](/preview/returns/) under Preview.
