Skip to content

Working with more than one programme

Goal: tell the API which programme a call is for, on a workspace that has more than one loyalty programme — each with its own rewards, balances, tiers and history.

A workspace starts with one programme, and while it has only one, program is optional. You create more on the console’s Programmes page, up to ten per workspace. This guide describes what changes once a workspace has several. On such a workspace a member can belong to several programmes. Points earned in one are never spent in another, so every read and write that touches a member’s points belongs to one programme.

The calls that read or move a member’s points, or list a programme’s rewards, take a program:

CallWhere program goes
GET /v1/rewards (and its alias GET /v1/catalogue)query string
GET /v1/customers/{channel}/{externalId}/balance, /status, /historyquery string
GET /v1/members/{uuid}/balance, /status, /historyquery string
GET /v1/members/top, GET /v1/customers/searchquery string
POST /v1/redemptions, POST /v1/discounts/evaluatebody field

It is the programme’s handle (for example vv) or its id, in lower case. Both name the same programme, so use whichever you keep. A value shaped like a UUID is always read as an id: a programme can never be given a handle that looks like one.

Terminal window
curl "https://sandbox.usetessera.io/v1/customers/shopify/cust_5512/balance?program=vv" \
-H "Authorization: Bearer $TESSERA_SECRET_KEY"
Terminal window
curl https://sandbox.usetessera.io/v1/redemptions \
-H "Authorization: Bearer $TESSERA_SECRET_KEY" \
-H "Idempotency-Key: ord_9001-redeem" \
-H "Content-Type: application/json" \
-d '{ "program": "vv", "customer_channel": "shopify", "customer_external_id": "cust_5512",
"requested_points": 500, "cart": { "channel": "api", "lines": [ … ] } }'

Every other call does not take program: reading a redemption, finalizing or releasing one (the hold already belongs to a programme), creating or linking a customer, and ingesting an event. A program query parameter on them is ignored; a body field program on finalize is refused (400 invalid_request), and on POST /v1/events it is refused (422 invalid_payload).

  • A workspace with one programme needs no program, and naming it is harmless. Nothing about an existing integration changes until you send one.
  • A workspace with several programmes refuses a call that names none: 400 with error.code program_required. There is no default programme for these calls, so a missing program is never answered with another programme’s numbers.
Statuserror.codeWhen
400invalid_requestprogram is not a lower-case programme id or a handle (upper case, spaces, empty, more than 40 characters), or is given more than once.
400program_requiredThe workspace has several programmes and the call named none.
404not_foundprogram names no programme of this workspace. A programme of another workspace looks exactly the same, and so does a handle that has since been renamed. With a publishable key, a programme that is not active (it is not the default and claims no sales channel) looks the same too.

A member who has not joined a programme reads zeros there; it is not an error.

GET /v1/rewards answers Cache-Control: private, max-age=300. A cache keys on the whole URL, query string included, so ?program=vv and ?program=loyalty are cached separately. Keep program in the URL (do not send it in a header or strip it) if you cache these responses yourself.

A redemption’s Idempotency-Key is tied to the programme the request named. The handle and the id of one programme are the same request, so a retry may spell it either way. Reusing a key with a different programme — or with a programme where the first request named none — is 409 idempotency_key_reuse, never a second hold.

An order you send to POST /v1/events is routed to a programme by where it came from: sales_channel, which a programme claims in the console. The event itself can never name a programme. See Routing an order to a programme.

SDK 0.8.0 and later carry the programme on the client:

const tessera = new TesseraClient({ secretKey: process.env.TESSERA_SECRET_KEY, program: 'vv' });
const sameClientForVv = tessera.withProgram('vv'); // or derive one

program goes on rewards.list, the member reads (balance, status, history), redemptions.place / member.redeem and discounts.evaluate, and on nothing else. A value that is not a handle or a lower-case id throws a config_error before any request. events.ingest takes a salesChannel, sent only when you give one.

GET /v1/programs/{ref} returns one programme by handle or by id, and GET /v1/programs lists them all. The answer carries the six things a storefront or a server integration needs to show and to address a programme:

Terminal window
curl "https://sandbox.usetessera.io/v1/programs/copperline-cellar" \
-H "Authorization: Bearer $TESSERA_PUBLISHABLE_KEY"
200
{ "id": "3f2504e0-4f89-41d3-9a0c-0305e82c3301", "handle": "copperline-cellar", "name": "Copperline Cellar Club", "points_label": "bottles", "active": true, "is_default": false }

name is null until the merchant sets a programme name, and points_label is points until they set one. The one-programme read is open to a publishable key and may be cached for up to five minutes. A programme that is not the workspace’s is 404, and so is an inactive one for a publishable key. A secret key or an OAuth token reads an inactive programme with "active": false. The list is for secret keys and OAuth read tokens only (a publishable key gets 403 publishable_key_forbidden), includes inactive programmes, and is never cached.

SDK programs.get(ref) and programs.list() return Program objects: the programme’s six fields, and the programme-scoped calls bound to it.

const club = await tessera.programs.get('copperline-cellar');
await club.rewards.list();
await club.tiers.list();
await club.member('cust_5512').balance(); // secret key
await club.member('cust_5512').redeem({ requestedPoints: 500, cart }, { idempotencyKey });
await club.discounts.evaluate({ externalId: 'cust_5512', cart });
club.cartAttributes(); // [{ key: 'tessera_program', value: 'copperline-cellar' }]

A Program acts in the programme it was fetched for, whatever programme the client names. It binds the programme’s id, which never changes, so a handle that is later re-assigned cannot move it. It has no withProgram, no client and no other resource, and tiers.list() takes no argument. A Program is a snapshot: its name, pointsLabel, active and handle do not update. Fetch one per request or per page load; do not keep one for a session. If the API’s answer is not the programme you asked for, programs.get throws a TesseraError with the SDK-local code invalid_response.

On Shopify’s online store the theme routes a cart to its programme for you. A headless storefront (Hydrogen, a custom front end) builds its own cart, so it names the programme itself: set the tessera_program cart attribute to the programme’s handle before checkout. The checkout discount for that programme then applies.

cartAttributes() returns exactly that attribute — and [] when the client names no programme, so the default programme’s discounts apply. It makes no request:

const vv = new TesseraClient({ secretKey: process.env.TESSERA_SECRET_KEY, program: 'vv' });
vv.cartAttributes(); // [{ key: 'tessera_program', value: 'vv' }]

Pass the result as the attributes of the Storefront API’s cartCreate or cartAttributesUpdate. A member’s discount applies when Shopify knows who the buyer is, so a headless cart also needs the signed-in customer’s Customer Account API access token on its buyer identity. A guest cart gets no member discount.

The attribute carries the handle, not the id: a client built with an id throws a config_error from cartAttributes() rather than return a value that routes to no discount.

A headless storefront can also let a signed-in member spend points at Shopify’s checkout. Your server places the redemption with a secret key, then your front end puts the returned ref on the cart. A secret key vouches for the customer, as it does for every other /v1 write, so never call this from the browser.

const redemption = await vv.checkoutRedemptions.place({
externalId: '1234567890',
requestedPoints: 500,
lines: [{ lineId: 'l1', productId: 'gid://shopify/Product/8801', quantity: 1, lineSubtotalCents: 4200 }],
});
// { ref, program: 'vv', kind: 'points', valueCents: 500, expiresAt, redemptionId }
const attributes = vv.cartAttributes({ ref: redemption.ref });
// [{ key: 'tessera_program', value: 'vv' }, { key: 'tessera_redemption', value: redemption.ref }]

externalId is the Shopify customer’s numeric id (not the gid:// form). lines is the cart as your server asserts it (productId is the Shopify product id in its gid://shopify/Product/<id> form, as a Storefront API cart line gives it in merchandise.product.id), and it is required for both shapes, as it is for POST /v1/redemptions: without the cart a Points redemption prices to nothing, so a request with no lines is a 400 invalid_request. An empty lines: [] is accepted and answers 422 option_not_eligible. The checkout prices the real cart, so an overstated line reserves points that never land. A Fixed reward card takes { externalId, optionId, lines } instead of requestedPoints; the HTTP calls are POST /v1/checkout-redemptions (with a required Idempotency-Key) and POST /v1/checkout-redemptions/{ref}/cancel.

Then, on the cart:

  1. Set both attributes, tessera_redemption and tessera_program, together. The Storefront API’s cartAttributesUpdate replaces the whole attribute set, so merge them with the attributes the cart already has.
  2. Put the signed-in customer’s Customer Account API access token on the cart’s buyer identity. The discount applies only when the checkout’s buyer is the customer the redemption was placed for.
  3. Send the shopper to checkout. The points are spent when the order is paid.

Things to plan for:

  • A redemption holds the points until expires_at. A cart that outlives it gets no discount, and a redemption that never reaches a checkout blocks that member’s other redemptions until it expires. Call checkoutRedemptions.cancel(ref, { externalId }) when the shopper abandons it. It answers released: false for one that was already resolved.
  • Find a redemption whose place response you lost. checkoutRedemptions.list({ externalId }) (GET /v1/customers/shopify/{externalId}/checkout-redemptions) returns what the customer holds now in the client’s programme, oldest first, each with its ref, points, expiresAt and the idempotencyKey it was placed with. Match your own placement on that key exactly, and pass your own idempotencyKey to place: a key the SDK generated is not carried on a timeout error. A redemption under a different key may be the member’s newer one, so do not cancel it, and never place again with the old key to recover. A redemption past expiresAt that has not been released yet is still listed, still holds points, and can still be cancelled. A list taken while the original request is still running can be empty.
  • One redemption is active per member in each programme. Placing points over a points redemption replaces it; anything else is 409 not_stackable. The Online Store and your headless storefront share that rule and one redemption velocity limit.
  • The member must be enrolled in the programme (404 not_enrolled), have a linked Shopify customer (404 customer_not_found), and the workspace needs a connected Shopify store (409 shopify_not_connected).
  • Only a Points value or a Fixed reward card can be placed this way. A Product reward card is refused with 422 option_not_eligible (details.reason card_not_placeable): /v1 has no live check of the reward product, so the refusal is the safe answer. Redeem those through the Online Store. Right after the store is connected or reconnected, and before the checkout sync has run, a placement is 422 option_not_eligible with details.reason card_not_at_checkout: the card is not at checkout yet, so retry later.
  • A secret key can cancel any checkout redemption in its workspace for the customer it names, including one the Online Store placed. A server cancel that lands while the shopper is mid-checkout normally drops the discount at payment. If the order is paid with the discount anyway (Shopify could not be updated in time), Tessera records it as an anomaly and claws the points back from the member.
  • Retrying. A 503 redemption_unavailable means the checkout could not be armed. Nothing is held, and the Idempotency-Key is spent: retry with a new key. The SDK does not retry it for you. A 409 conflict on place means this Idempotency-Key’s earlier attempt is already resolved: it was rolled back (you may not have received that 503), cancelled, used at checkout, or it expired. No redemption is pending under this key; to redeem again, place with a new key. Any other network error or 5xx is retried by the SDK with the same key, which is safe.