Skip to content

Preview what an event would earn

POST
/earn/preview

What would this event earn, now? Evaluates the published programme version in force against the event you describe and returns the points per rule, without booking anything: nothing is written, no Idempotency-Key is needed, and an unknown member is previewed as a new one. Publishable key OK for a generic preview (no external_id), which is privately cacheable for 60 seconds; naming a member needs a secret key and is never cached. A matched rule whose input you did not send is listed in skipped, never guessed, and accrues_as_sent is false when booking this exact event would not accrue as sent. An overwrite campaign the input cannot decide is 422 preview_input_required, because answering could misstate what the member earns.

What would this event earn? The body is a POST /v1/events body with every field optional, so an event you are about to book can be previewed as it is. Send at least one of amount, items or units. source_ref, idempotency_key, order_ref, email and phone are accepted and have no effect. type must be purchase if sent (anything else is 422 event_type_not_earnable). Naming a member (external_id, which needs the channel it lives on) previews that member and requires a secret key; an unknown member is previewed as a new one. channel and/or sales_channel without external_id is a generic preview, routed to a programme exactly as an event with those fields would be. occurred_at is honoured for a secret key (the rules are judged at that instant); a publishable key is always judged at the server’s now. tenant, if sent, must be the key’s own tenant. trigger narrows the preview to one trigger; omitted, every trigger the programme hooks is summed.

object
channel
string
external_id
string
type
string
Allowed values: purchase refund referral review profile
source_ref
string
idempotency_key
string
occurred_at
string format: date-time
tenant
string
trigger
string
Allowed values: order_placed payment_captured fulfillment
order_ref
string
sales_channel

The sales channel this order came through, for programme routing. A key such as shopify:web: lower-case letters, digits and : . _ -, starting with a letter or digit, up to 64 characters. Optional. An order with none is keyed by its channel: a channel that already fits the key shape is the key as it is (acme:pos stays acme:pos); any other channel is lower-cased, 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. It does not name a programme, and a refund ignores it (a refund follows its order).

string
/^[a-z0-9][a-z0-9:._-]{0,63}$/
amount
object
gross
integer
net_of_tax_shipping
integer
final_after_discounts
integer
currency
string
>= 3 characters <= 3 characters
refunded_base
integer
> 0
order_base
integer
> 0
email
string
>= 3 characters <= 320 characters
phone
string
>= 3 characters
items
Array<object>
<= 200 items
object
product_id
required
string
>= 1 characters <= 120 characters
collection_ids
Array<string>
default: <= 50 items
quantity
integer
default: 1 > 0
unit_price_cents
integer
refunded_amount_cents
integer
units
Array<object>
<= 20 items
object
unit
required
string
/^[a-z][a-z0-9_]{0,31}$/
value
required
integer
program

The programme to act in: its handle (for example vv) or its lower-case id. Optional on a workspace with one programme; on a workspace with several, a call that names none is refused with 400 program_required. A programme that is not this workspace’s is 404 not_found.

string

The preview.

object
program_id
required

The programme that was previewed.

string format: uuid
evaluated_at
required

The instant the rules were judged at.

string format: date-time
personalised
required

True when a member was named (secret key): their tier and cap headroom were applied.

boolean
tier_key
required

The tier applied to a personalised preview; null for a generic one, or a member with none.

string | null
points
required

The sum of the listed rules.

object
spendable
required
integer
qualifying
required
integer
rules
required

Only rules that contributed. A rule an active overwrite campaign suppresses is not listed.

Array<object>
object
rule_id
required
string
name
required

The rule’s name. A publishable key can see the names of the rules live now, so name them as you would show a customer.

string
trigger
required

The event trigger this rule hooks.

string
Allowed values: order_placed payment_captured fulfillment
campaign
required
boolean
spendable
required

Spendable points this rule contributes (after the tier multiplier, for a member, and the cap).

integer
qualifying
required

Qualifying credits this rule contributes.

integer
capped
required

True when a cap reduced this rule’s earn. A generic preview, an unknown member and a member new to the programme are capped at the rule’s whole cap; a known member at what is left of it.

boolean
skipped
required

Matched rules that could not be evaluated for want of an input. Never guessed.

Array<object>
object
rule_id
required
string
name
required
string
needs
required

The input the rule reads that the request did not carry.

string
Allowed values: amount items units
accrues_as_sent
required

False when booking this exact event would be refused, stuck or credited differently: no channel was sent (an ingested event requires one; a member’s channel counts), a matched rule was skipped, no trigger was sent, the member would not be enrolled (opt-in programme), program names a programme other than the one ingest would route the event to (the claimant of the sales channel, else the default programme), or a publishable key sent an occurred_at that was ignored. A generic preview (no member) assumes the booker can earn: under opt_in enrollment, that they have joined. Not a promise of the exact figure: an order already pinned to another programme, a concurrent earn against a cap, an already-booked source_ref and a catalog channel’s collection data can still differ.

boolean

A malformed body, none of amount / items / units, an external_id without a channel, the program is malformed (not a lower-case programme id or a programme handle), or a workspace with several programmes was given no program and no routing input (channel / sales_channel) (program_required).

object
error
required
object
code
required
string
Example
not_found
message
required
string
details
request_id
required
string
Example
req_9f8e7d6c5b4a3210

Missing or invalid API key or OAuth credential.

object
error
required
object
code
required
string
Example
not_found
message
required
string
details
request_id
required
string
Example
req_9f8e7d6c5b4a3210

A publishable key named a member (publishable_key_forbidden), or an OAuth token lacks the loyalty:read scope needed to name one (insufficient_scope).

object
error
required
object
code
required
string
Example
not_found
message
required
string
details
request_id
required
string
Example
req_9f8e7d6c5b4a3210

No published programme version is in force (program_not_published), tenant is not this credential’s tenant, or the program names no programme of this workspace (not_found).

object
error
required
object
code
required
string
Example
not_found
message
required
string
details
request_id
required
string
Example
req_9f8e7d6c5b4a3210

type is not purchase (event_type_not_earnable), an overwrite campaign cannot be decided from the input sent (preview_input_required, details.needs names the input), or a value is malformed (the rule’s own code).

object
error
required
object
code
required
string
Example
not_found
message
required
string
details
request_id
required
string
Example
req_9f8e7d6c5b4a3210