Skip to content

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.

FieldRequiredNotes
channel / external_idyesResolves (or creates) the member — see Members & channels.
typeyesOne of purchase, refund, referral, review, profile.
source_refyesYour ID for the underlying thing (an order ID, a review ID) — travels with the ledger entry as provenance.
idempotency_keyyesDedup key for this exact event — namespace it, e.g. shopify:ord_9001-purchase. See Idempotency.
occurred_atyesISO-8601 timestamp of when the event happened.
triggernoWhich lifecycle moment this is — one of order_placed, payment_captured, fulfillment — used by your programme’s rule-matching (trigger) logic.
sales_channelnoThe 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.
amountno (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.
itemsno, but recommended for condition-based programsLine 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.
unitsno, but required for units-based programsTyped 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.

Terminal window
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" }
}'
201 (accepted) / 200 (duplicate or skipped)
{
"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
}

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.

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_channel names 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. Without sales_channel, the key comes from your channel value:
    • A channel that 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, so acme:pos stays acme:pos.
    • Any other channel is lowercased, and each run of characters outside a-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 is unknown. So Acme POS becomes acme-pos and !!! becomes unknown.
  • 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 refund follows its order whatever sales_channel it carries.
  • The body cannot name a programme: program_id or any other programme field is a 422 (invalid_payload).

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.

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.

{ 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.

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.

codeStatusCause
invalid_request400Malformed body (wrong types / missing required fields).
signature_invalid / replay_detected401Bad or missing signature, stale timestamp, or reused nonce.
idempotency_key_conflict409The Idempotency-Key header didn’t match the body’s idempotency_key.
invalid_payload / unsupported_event_type422The body failed the event contract, or type isn’t recognized.

See Error handling for retry patterns and Errors & the envelope for the full catalogue.