Overview
OneCard customers show a barcode (Code128) in the OneCard app. The barcode is the customer's membership code, for example OC-BK3E-D2BT. It contains no personal data.
There are two ways a till can work with OneCard:
- Card at the till. The till's scanner reads the card, and the till sends the sale with the membership code. Points are awarded straight away and the till gets the new balance back.
- Sale only. The till has no scanner, or the customer shows the card after paying. The till sends the sale without a code. It waits for up to 30 minutes until a member of staff scans the customer's card in the OneCard Shop app and picks the sale.
Either way the till never calculates points and staff never retype amounts.
Getting access
- Request access. The till supplier or the shop fills in the API access form.
- OneCard approves the shop for API access. We'll reply by email, usually within two working days.
- The shop owner creates a key in the OneCard Shop app: Settings → Till / POS connection → Create key. The key looks like
oc_live_followed by 32 letters and digits. - The key is shown once. The owner enters it into the till's settings or sends it to you through a secure channel. OneCard stores only a hash; a lost key can't be recovered, only revoked and replaced.
Each key belongs to exactly one shop. A till supplier serving many shops holds one key per shop. Keep keys on the till or your server, never in a web page or mobile app that customers can download.
Basics
| Base URL | https://api.onecarduk.shop/api/v1 |
|---|---|
| Auth | Authorization: Bearer oc_live_… (the shop's key) |
| Format | JSON in and out, UTF-8, HTTPS only |
| Money | Integer pence, for example £12.50 is 1250 |
| Idempotency | Send an Idempotency-Key header (8 to 128 characters, unique per operation) on every POST |
| Rate limit | 120 requests a minute per key (60 a minute for refunds and redemptions) |
| Times | ISO 8601 with offset, for example 2026-11-19T14:05:00Z |
In the examples below $ONECARD_KEY holds the shop's key and $API is the base URL.
Till flows
Endpoints
GET/pos/ping
Checks the key and returns the shop it belongs to. Call it when the key is entered in the till's settings and show the shop name so staff can confirm it.
curl -s "$API/pos/ping" -H "Authorization: Bearer $ONECARD_KEY"
{ "ok": true, "shop": { "id": "…", "name": "Dev Coffee House", "currency": "GBP" } }
GET/pos/customers/{code}
Call this when the till scans a OneCard. It returns what the till may show: the customer's first name, their balance at this shop and the rewards they can claim. The first time a shop looks up a card, the customer is enrolled at that shop (newlyEnrolled: true).
curl -s "$API/pos/customers/OC-BK3E-D2BT" -H "Authorization: Bearer $ONECARD_KEY"
{
"firstName": "Emma",
"membershipId": "OC-BK3E-D2BT",
"balance": 120,
"availableRewards": [
{ "offerId": "off_123", "title": "Free coffee", "pointsRequired": 100, "state": "unlocked" }
],
"nextReward": { "offerId": "off_456", "title": "Free croissant", "pointsRequired": 200, "state": "locked" },
"newlyEnrolled": false
}
Codes are checked with a check character, so a misread barcode returns 400 INVALID_MEMBERSHIP_CODE and a valid code that isn't a OneCard member returns 404 NOT_FOUND. In both cases ask the cashier to scan again or type the code.
POST/pos/sales
Send each completed sale once, after payment. receiptRef is your unique receipt or transaction number for this shop: OneCard will never award points twice for the same receipt.
| Field | Type | Notes |
|---|---|---|
amountMinor | integer, required | Total paid in pence, after discounts. Must be above 0. |
receiptRef | string, required | 1 to 64 characters: letters, digits and . _ : / # - |
membershipCode | string, optional | The scanned card. Leave it out to create a waiting sale. |
items | array, optional | Up to 200 of { sku, name?, qty, unitMinor? } |
occurredAt | date-time, optional | When the sale happened. Defaults to now. |
With a card: points awarded now
curl -s -X POST "$API/pos/sales" \
-H "Authorization: Bearer $ONECARD_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: sale-R-000123" \
-d '{
"membershipCode": "OC-BK3E-D2BT",
"amountMinor": 1250,
"receiptRef": "R-000123",
"items": [
{ "sku": "LATTE-L", "name": "Large latte", "qty": 2, "unitMinor": 375 },
{ "sku": "CROISSANT", "qty": 2, "unitMinor": 250 }
]
}'
// Node 18+ or any runtime with fetch. Keep the key on the till or your server.
const API = 'https://api.onecarduk.shop/api/v1';
async function sendSale({ membershipCode, amountMinor, receiptRef, items }) {
const res = await fetch(`${API}/pos/sales`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.ONECARD_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': `sale-${receiptRef}`, // same key on every retry of this sale
},
body: JSON.stringify({ membershipCode, amountMinor, receiptRef, items }),
signal: AbortSignal.timeout(10_000),
});
const body = await res.json();
if (!res.ok) throw Object.assign(new Error(body.error.message), body.error, { status: res.status });
return body;
}
const result = await sendSale({ membershipCode: 'OC-BK3E-D2BT', amountMinor: 1250, receiptRef: 'R-000123' });
console.log(`+${result.pointsAwarded} pts, balance ${result.balance}`);
Response 201:
{
"status": "awarded",
"transactionId": "…",
"receiptRef": "R-000123",
"pointsAwarded": 12,
"balance": 132,
"unlockedRewards": [ … ],
"newlyEnrolled": false,
"replayed": false,
"customer": { "firstName": "Emma", "balance": 132, "availableRewards": [ … ], "nextReward": { … } }
}
Without a card: a waiting sale
Leave out membershipCode. The sale appears in the OneCard Shop app for 30 minutes. When staff pick it and scan the customer's card, the points are awarded. If the till later sends the same receiptRef with a membershipCode, the waiting sale is settled instead.
curl -s -X POST "$API/pos/sales" \
-H "Authorization: Bearer $ONECARD_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: sale-R-000124" \
-d '{ "amountMinor": 640, "receiptRef": "R-000124" }'
{
"status": "pending",
"sale": {
"id": "…", "receiptRef": "R-000124", "amountMinor": 640, "items": [],
"status": "pending", "occurredAt": "2026-11-19T14:05:00.000Z",
"expiresAt": "2026-11-19T14:35:00.000Z", "createdAt": "2026-11-19T14:05:00.000Z"
},
"replayed": false
}
POST/pos/sales/{receiptRef}/refund
Call this when a sale is refunded. If points were awarded they are taken back; if the sale was still waiting it is cancelled. Calling it again is safe and returns replayed: true. The body is optional.
curl -s -X POST "$API/pos/sales/R-000123/refund" \
-H "Authorization: Bearer $ONECARD_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: refund-R-000123" \
-d '{ "reason": "Customer returned items" }'
{ "status": "refunded", "receiptRef": "R-000123", "pointsReversed": 12, "balance": 120, "replayed": false }
A waiting sale returns { "status": "cancelled", "receiptRef": "R-000124" }. Partial refunds aren't supported yet: refund the sale and send a new one for the amount kept, with a new receiptRef.
POST/pos/redemptions
Redeem a reward the customer chose from availableRewards. The points are deducted and a reference code is returned to print on the receipt. Idempotency-Key is required.
curl -s -X POST "$API/pos/redemptions" \
-H "Authorization: Bearer $ONECARD_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6f1c2b8e-0c7a-4c1e-9d55-2f7a1d2b9e10" \
-d '{ "membershipCode": "OC-BK3E-D2BT", "offerId": "off_123" }'
{
"redemption": { "id": "…", "code": "7KQ2M9XDPA", "offerTitle": "Free coffee", "pointsSpent": 100 },
"balance": 32,
"replayed": false
}
import { randomUUID } from 'node:crypto';
async function redeem(membershipCode, offerId) {
const res = await fetch(`${API}/pos/redemptions`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.ONECARD_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': randomUUID(), // store it with the basket so a retry reuses it
},
body: JSON.stringify({ membershipCode, offerId }),
});
const body = await res.json();
if (!res.ok) throw Object.assign(new Error(body.error.message), body.error, { status: res.status });
return body; // { redemption: { code, offerTitle, pointsSpent }, balance }
}
Errors & retries
Errors always have the same shape:
{ "error": { "code": "RECEIPT_ALREADY_AWARDED", "message": "Points were already awarded for this receipt", "details": null } }
| Status | Code | What to do |
|---|---|---|
| 400 | VALIDATION_ERROR | Fix the request. details lists each field problem. |
| 400 | IDEMPOTENCY_KEY_REQUIRED, IDEMPOTENCY_KEY_INVALID | Send an Idempotency-Key of 8 to 128 characters. |
| 400 | INVALID_MEMBERSHIP_CODE | The scanned code is not a OneCard code (often a misread). Scan again. |
| 401 | UNAUTHENTICATED | The key is missing, wrong or revoked. Ask the owner for a new key. |
| 403 | FORBIDDEN | The shop is not active or API access is not enabled for it. |
| 404 | NOT_FOUND | Unknown card, sale or reward. Scan again or check the reference. |
| 409 | RECEIPT_ALREADY_AWARDED | This receipt already earned points. Treat as done; do not retry. |
| 409 | RECEIPT_CONFLICT | The same receiptRef was sent with a different amount. Check your receipt numbering. |
| 429 | RATE_LIMITED | Wait and retry with back-off. |
| 5xx | Retry with the same Idempotency-Key. |
Retrying safely
- Use a timeout of about 10 seconds. On a timeout, network error, 429 or 5xx, retry with the same
Idempotency-Keyand body after 1 s, 2 s, 4 s and so on, up to about a minute. - A retried request that already succeeded returns the original result with
replayed: true. - Never block the sale on OneCard. If OneCard can't be reached, finish the sale and send it later from a queue; the customer still gets the points within the 30-minute window or when staff attach it.
Printing on the receipt
After an awarded sale, print a short loyalty block using the response:
--------------------------------
OneCard · Hi Emma
Points this visit: +12
Balance at Dev Coffee House: 132
Free coffee is ready to claim!
--------------------------------
- Print the first name only; never print the full membership code. If you print it at all, mask it:
OC-••••-D2BT. - Use
unlockedRewardsfor "ready to claim" lines andcustomer.nextRewardfor "88 points to a Free croissant". - For a waiting sale, print "Show your OneCard to staff within 30 minutes to collect your points".
- For a redemption, print the reward title and the
redemption.code.
Test checklist
Ask us for a test shop when you request access. Before going live, check each item:
GET /pos/pingshows the right shop name in your settings screen.- Scanning a OneCard barcode (Code128) in the app fills in the membership code, with or without dashes.
- A sale with a card returns
pointsAwardedand the balance is printed on the receipt. - The same sale sent twice (same
receiptRef) does not award points twice. - A network failure mid-request is retried with the same
Idempotency-Key. - A sale without a card appears in OneCard Shop under waiting till sales and can be claimed by scanning the card.
- A refund takes the points back; refunding twice is harmless.
- A reward from
availableRewardscan be redeemed and its code printed. - Amounts are in pence after discounts (a £12.50 sale is
1250). - A revoked key shows a clear "key not valid" message to staff.
- The till keeps working when OneCard is unreachable.
Ready? Request API access or read the full API reference.