Idempotency
A network timeout leaves you not knowing whether an event arrived. Resend it with the same key, and the API makes sure the member earns once. POST /events takes that key two ways: an eventReference in the body, or an Idempotency-Key header.
eventReference
eventReference is your own id for what happened: an order number, a receipt id, a check-in id. Send it on every event that has one.
curl -X POST "https://api.loomloyalty.com/events?entityType=CUSTOMER&entityId=cust_123" \
-H "Authorization: Bearer $LOOM_API_KEY" -H "Content-Type: application/json" \
-d '{ "eventTypeCode": "purchase", "eventReference": "order-5001",
"description": "Order 5001", "amount": 42.50 }'
Send the same eventReference again and the API answers 409 with code EVENT_ALREADY_PROCESSED; no rule runs a second time. A 409 on a retry means the first one got through, so treat it as success.
The reference is part of the event, so it is stored with it and shown wherever the event is.
Idempotency-Key
When the event has no natural id, or you want retries keyed by your own request id, send an Idempotency-Key header (1 to 255 characters):
curl -X POST "https://api.loomloyalty.com/events?entityType=CUSTOMER&entityId=cust_123" \
-H "Authorization: Bearer $LOOM_API_KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: register-3-sale-0042" \
-d '{ "eventTypeCode": "purchase", "description": "Register 3 sale", "amount": 12.00 }'
The event's id is derived from the key, your environment and the customer you named, so every resend with that key maps to the same event:
- While the first is still queued, a resend returns the same
eventIdand isn't processed again. - Once the first is processed, a resend returns
409 EVENT_ALREADY_PROCESSED. - A resend with a different body still maps to the first event. The key, not the body, decides.
- A blank or longer key is refused with
400 EVENT_IDEMPOTENCY_KEY_INVALID.
When you send both, the header wins and eventReference is only stored.
Which to use
| Situation | Send |
|---|---|
| The event has an order, receipt or transaction id | eventReference |
| A retry layer that already gives each request an id | Idempotency-Key |
| Neither | Generate a UUID per event and send it as Idempotency-Key, keeping it for retries |
Without either, every request is a new event, and a retried purchase earns twice.
Scope
A key or reference is unique per environment and customer. The same eventReference on two different customers is two events, and your development and production environments never collide.
Retrying
Retry 429, 503 and other 5xx responses with backoff (see Rate Limits), reusing the same key each time. Don't change the key between retries, or you lose the protection.
Cart preview requests (simulate=true) record nothing, so both are ignored there.