Earning events
Goal: report a business event so Tessera’s earn engine can accrue points for it.
POST /v1/events is signed, idempotent, and channel-agnostic — the same shape whether the event
came from Shopify, a POS, or your own backend.
Request
Section titled “Request”| Field | Required | Notes |
|---|---|---|
channel / external_id | yes | Resolves (or creates) the member — see Members & channels. |
type | yes | One of purchase, refund, referral, review, profile. |
source_ref | yes | Your ID for the underlying thing (an order ID, a review ID) — travels with the ledger entry as provenance. |
idempotency_key | yes | Dedup key for this exact event — namespace it, e.g. shopify:ord_9001-purchase. See Idempotency. |
occurred_at | yes | ISO-8601 timestamp of when the event happened. |
trigger | no | Which lifecycle moment this is — one of order_placed, payment_captured, fulfillment — used by your programme’s rule-matching (trigger) logic. |
sales_channel | no | The sales channel this order came through, as a key such as shopify:web or hydrogen:vv: lowercase letters, digits and : . _ -, starting with a letter or digit, up to 64 characters. See Routing an order to a programme. |
amount | no (required in practice for purchase/refund) | { net_of_tax_shipping, gross, final_after_discounts, currency, ... }, minor units. Extra sub-fields your connector sends are accepted and ignored. |
items | no, but recommended for condition-based programs | Line items: [{ product_id, collection_ids, quantity, unit_price_cents, refunded_amount_cents }] (up to 200). A program rule with a product/collection condition can only match against items your event actually carries — an event with no items simply never matches those conditions (fail-closed, never an over-earn). collection_ids defaults to [] and quantity to 1 per item when omitted. unit_price_cents (an order item’s per-unit price, minor units) is required for the item_subtotal earn base; refunded_amount_cents (a refund item’s line total for this refund, minor units) applies only to refund events. |
units | no, but required for units-based programs | Typed non-monetary quantities this event carries: [{ unit, value }] (up to 20). unit is a slug (^[a-z][a-z0-9_]{0,31}$); value is a non-negative integer. One entry per unit — a duplicate key is a 422 (invalid_payload), not a silent sum. See Earning on units, not money. |
The body is strict snake_case — an unrecognized top-level field is a loud 422
(invalid_payload), never silently dropped.
curl -X POST https://sandbox.usetessera.io/v1/events \ -H "Authorization: Bearer $TESSERA_SECRET_KEY" \ -H "Content-Type: application/json" \ -H "X-Loyalty-Signature: v1=<computed>" \ -H "X-Loyalty-Timestamp: 1721000000" \ -H "X-Loyalty-Nonce: 7c9e6679-7425-40de-944b-e07fc1f90ae7" \ -H "Idempotency-Key: shopify:ord_9001-purchase" \ -d '{ "channel": "shopify", "external_id": "cust_5512", "type": "purchase", "source_ref": "ord_9001", "idempotency_key": "shopify:ord_9001-purchase", "occurred_at": "2026-07-24T12:00:00Z", "trigger": "payment_captured", "amount": { "net_of_tax_shipping": 4200, "currency": "USD" } }'{ "event_id": "evt_...", "customer_id": "c0ffee00-0000-4000-8000-000000000001", "channel": "shopify", "source_ref": "ord_9001", "type": "purchase", "status": "accepted", "customer_created": false, "linked_via": "shopify", "enqueued": true}const event = await tessera.events.ingest({ type: 'purchase', channel: 'shopify', externalId: 'cust_5512', sourceRef: 'ord_9001', idempotencyKey: 'shopify:ord_9001-purchase', occurredAt: new Date(), trigger: 'payment_captured', amount: { netOfTaxShipping: 4200, currency: 'USD' },});console.log(event.status); // 'accepted' | 'duplicate'The SDK signs the request for you from the signingSecret you configured on the client.
enqueued: true means the event was accepted and handed to the earn engine — accrual is
asynchronous, so a balance read immediately after may not reflect it yet.
Routing an order to a programme
Section titled “Routing an order to a programme”Each order is routed to a programme the first time Tessera sees it, and every later event for that order (another trigger, a redelivery, a refund) stays with it.
sales_channelnames where the order came from. A programme that claims that key in the console receives the order; an order whose key no programme claims goes to the default programme. Withoutsales_channel, the key comes from yourchannelvalue:- A
channelthat already fits the key shape (lower-case letters, digits and: . _ -, starting with a letter or digit, up to 64 characters) is the key as it is, soacme:posstaysacme:pos. - Any other
channelis lowercased, and each run of characters outsidea-z 0-9 . _ -(a space or a:included) becomes one-. Leading characters that are not a letter or digit are dropped, the result is cut to 64 characters, and trailing-characters are dropped. If nothing is left, the key isunknown. SoAcme POSbecomesacme-posand!!!becomesunknown.
- A
- An unknown or unclaimed key is never rejected, so an order is never lost to a routing setting. A malformed key is a
422(invalid_payload). - A claim changed later does not move an order already seen.
- A
refundfollows its order whateversales_channelit carries. - The body cannot name a programme:
program_idor any other programme field is a422(invalid_payload).
Earning on units, not money
Section titled “Earning on units, not money”Some programs earn on a quantity that isn’t money — kilometers flown, nights stayed, minutes streamed, seats booked. Send the fact; let the program decide what it’s worth.
const event = await tessera.events.ingest({ type: 'purchase', channel: 'kestrel', externalId: 'cust_5512', sourceRef: 'bk_9001-sector-1', idempotencyKey: 'kestrel:bk_9001-sector-1', occurredAt: new Date(), trigger: 'order_placed', units: [{ unit: 'km', value: 5541 }],});Your code no longer computes the points. A rule can earn per unit (0.5 points per km) or per full block of units (5 points for every complete 100 km), and both can run on the same event. Change the rate in the program’s configuration, and the next event earns at the new rate — no deploy.
Values are integers — choose a finer unit for fractions
Section titled “Values are integers — choose a finer unit for fractions”There’s no per-unit scale field. To earn on half-hours send minutes, not fractional hours; for
part-kilometers send meters. A fractional value is a 422 (invalid_payload).
This is a deliberate trade: one integer quantity per unit is unambiguous under partial refunds, where a scale factor would have to be stored, versioned, and reasoned about on every reversal.
Scope your units rules
Section titled “Scope your units rules”A rule whose earn base names a unit the event does not carry is an error, not a zero — accrual for that event fails rather than quietly crediting nothing.
That’s deliberate: silently crediting zero for a unit you believe you’re earning on is the worse failure, because nothing tells you it happened. The cost is that an unscoped units rule fails every event that legitimately carries no units. Give a units rule a condition that limits it to the events that carry its unit.
Only an explicit zero is a zero
Section titled “Only an explicit zero is a zero”{ unit: 'km', value: 0 } is a legitimate “this sector flew no distance” and earns nothing.
Omitting km entirely is the error case above. The distinction matters: one says nothing
happened, the other says I have no idea whether anything happened.
Money and units can coexist
Section titled “Money and units can coexist”An event can carry both amount and units. Separate rules earn on each, and each leg reverses
under its own law — a partial money refund doesn’t touch the units leg, and a units refund doesn’t
borrow the monetary ratio. A refund can carry units too, to reverse exactly the quantity that was
returned.
Common errors
Section titled “Common errors”code | Status | Cause |
|---|---|---|
invalid_request | 400 | Malformed body (wrong types / missing required fields). |
signature_invalid / replay_detected | 401 | Bad or missing signature, stale timestamp, or reused nonce. |
idempotency_key_conflict | 409 | The Idempotency-Key header didn’t match the body’s idempotency_key. |
invalid_payload / unsupported_event_type | 422 | The body failed the event contract, or type isn’t recognized. |
See Error handling for retry patterns and Errors & the envelope for the full catalogue.