Skip to main content
Events are signals that trigger rule evaluation. Your application sends them through the API, or automations generate them on a schedule or in response to participant state changes. Scrip evaluates applicable ACTIVE rules across every rule set using the participant, group, and program state at the start of the event. See Event-start snapshot. Every event also has a source that says who produced it. It is separate from the event’s name, event_type.

Sending an event

The API returns 202 Accepted with a Location header that points at the event:
participant_id is omitted from the 202 body when you sent only external_id and Scrip has not resolved the participant yet. Rules can read the named recipient as recipient.id and recipient.external_id. Naming a recipient does not send rewards to them automatically. To credit them, set the action’s target to {"participant_id": "${{ recipient.id }}"}. Actions without a target still apply to the participant who triggered the event.

Timestamps

Every event carries two timestamps: These serve different roles:
  • event_timestamp is the time your rules see. It becomes the now variable in CEL expressions, so rule conditions that compare against time use the event’s occurrence time, not the current time. A retry gets the same now as the first attempt.
  • created_at is when Scrip received the event. The created_after and created_before query parameters on list endpoints filter on created_at, not event_timestamp. Use them to fetch everything since your last sync without missing events that arrive late. To filter by when events actually occurred, use occurred_after and occurred_before instead. You can combine both pairs, and an event must match every bound you send. All bounds are exclusive.
Because event_timestamp is customer-supplied, it can differ from created_at. A batch import might backdate events to last month, or clock skew might push timestamps slightly into the future. Rules evaluate against the current rule definitions regardless of event_timestamp. A backdated event runs against today’s rule definitions, but active_from / active_to windows are checked against the event’s event_timestamp, so a backdated event inside a past window still fires time-windowed rules. See Time-windowed rules.

After you send an event

Events process asynchronously. A 202 confirms receipt, not that rules have run. Program checks, participant resolution, and rule evaluation happen in the background. Existing participants are enrolled in the target program if they are not already members; see Programs: Enrollment. Validation errors surface as event.failed webhook events. Rule sets covers evaluation order and stop_after_match. Writing rules covers the event-start snapshot. Updating rules under live traffic covers what happens if you change a rule while events are still processing. To check processing status:
The response includes the event status, rule evaluations that occurred, and error details if processing failed. Each evaluation records the rule_set_id of the set the rule was in when it ran, and the list follows the set and rule order of that moment.

Wait for the result

A GET /v1/events/{event_id} within seconds of the 202 can return 404 event_not_found. That 404 means “not yet recorded”, not “lost”. Scrip accepts the event first and records it a moment later. Use one of two approaches:
  • Wait for the webhook. Subscribe an endpoint to event.completed and event.failed. Scrip sends one when processing finishes, and event.completed lists what the event changed. See Event outcome.
  • Poll a bounded number of times. Check once a second for about ten seconds. Treat 404, PENDING, and PROCESSING as “not finished yet”. Stop on COMPLETED or FAILED.
Handle both final statuses. A COMPLETED event with an empty rule_evaluations array means no rule matched. A FAILED event carries an error_message, and an error_code when the failure has one. A 404 that lasts past your bound does not mean Scrip lost the event. Check that you used the id from the 202, then keep checking with that same id, or wait for the webhook. If you no longer have the id, send the event again with the same idempotency_key; Scrip does not process it twice. The Quickstart has a complete polling loop in curl, Node, and Python. For a deeper view, use the impact endpoint to see everything an event caused:
The response is the event with its rule_evaluations, plus journal_entries with their postings, state_changes, and balance_impact, the net change for each entity, asset, and bucket. See Get event impact.

Execution guarantees

Rules use counters, tags, and balances to decide what participants earn. These guarantees explain what happens when events arrive at the same time.

One event at a time per participant

Scrip processes events for a given participant one at a time. The next event waits until the first finishes, then reads the participant’s updated state. This makes counter-based patterns safe when events arrive together. If two purchases arrive at the same moment for a participant whose purchase_count is 9, they cannot both see 9: one finishes first, and the other then sees 10. A milestone rule that checks int(participant.counter.purchase_count + 1.0) % 10 == 0 pays once, on the event that crosses the milestone. Events for different participants can run at the same time. This guarantee covers the participant’s own events. Another participant’s event can change their state through a target, and your app can change it with PATCH /v1/participants/{participant_id}. Those changes can happen while an event is running, without rechecking what it already read. For an exact counter milestone, update the counter only through that participant’s own events. A participant’s status is read when each balance, counter, or tier action runs, not when the event starts. If the participant is suspended while an event is processing, a later balance, counter, or tier action fails the whole event with participant_inactive.

Shared program and group state

When multiple participants share a program counter/tag or a group (such as a family account), their events can arrive at the same time.
  • Shared balances (GROUP or PROGRAM wallet) are serialized automatically, so concurrent credits and debits never overwrite each other.
  • Shared counters and tags (program.* or groups[*].*) are also checked for concurrent updates whenever a rule action writes to them (TAG, UNTAG, COUNTER, SET_ATTRIBUTE). If another event updated the same key while this event was evaluating, Scrip automatically refreshes the state or retries the event so that a shared milestone or cap only pays out once.
For example, this rule awards 500 points to the first participant to finish a challenge and sets a program-level tag so only one participant can win:
If two participants finish at the exact same moment, the second event sees challenge_winner already set, rolls back its CREDIT, and records SKIPPED with reason SHARED_STATE_CHANGED in rule_evaluations. When separating shared-counter updates and reward rules into different rule sets, put the rule that increments the shared counter in an earlier set (tracking) than the rule that checks it (earning).

Processing order is not guaranteed

One at a time does not mean in order. Events for one participant never run at the same time, but Scrip does not promise they run in the order you sent them. Two events sent moments apart usually process in that order, but automatic retries and the way Scrip picks up events can swap them, and an event that hits a temporary failure can retry after later events have already completed. event_timestamp never influences processing order; it only sets the now variable in CEL. Automation-generated events have no ordering relationship with events you send around the same time. A cron automation that fires at midnight sends its events on its own schedule, so a purchase sent near the boundary can process before or after the reset. Design for this by keeping rules order-tolerant. Accumulating counters, tag guards, and threshold checks written as (snapshot + event.amount) >= threshold reach the same totals regardless of arrival order, though which specific event crosses a threshold can differ. When the outcome genuinely depends on sequence, compute that fact in your backend and send it on the event instead of deriving it from processing order. For which side of a day, week, or month boundary a purchase belongs to, use a calendar counter: it files each event by its event_timestamp, whatever order events process in. See the spend threshold pattern for a worked example.

Failure is all-or-nothing

An event either completes with all of its effects or fails with none of them. If any action fails, Scrip undoes everything the event’s rules did. A FAILED event changes no balances, counters, tags, attributes, or tiers, so there is no partial state to reconcile. It keeps only its own record: its status, its error_message and, when the failure has one, its error_code, plus a FAILED evaluation when a rule’s action caused the failure. One thing stays. If Scrip created the participant or enrolled them in the program while recording the event, before any rule ran, they stay created and enrolled. Two cases continue instead of failing. A rule that would exceed its budget rolls back only its own actions, is recorded in rule_evaluations as skipped with reason BUDGET_EXCEEDED (program-wide budget) or PARTICIPANT_BUDGET_EXCEEDED (per-participant budget), and the remaining rules still run. A rule skipped with reason SHARED_STATE_CHANGED is handled the same way; see Shared program and group state. Because a failed event changed no balances or state, retrying it is safe. A retry, automatic or manual, runs every rule again from the start, so nothing from the failed attempt applies twice. The retry reads the participant’s state at retry time, not the state when the event first arrived. now is still the event’s event_timestamp.

Event lifecycle

Events for a SUSPENDED or CLOSED participant are processed, and their rules run. A balance, counter, or tier action fails the event with participant_inactive when the event’s participant, or the participant the action changes, is SUSPENDED or CLOSED, and the failed event keeps none of its changes. See Inactive participants and events.
Failed events carry a machine-readable error_code (when the failure has a classified code, such as participant_inactive or program_inactive) on the event resource and the event.failed webhook event, so you can branch on failure type without string-matching the error message. If you have webhook endpoints configured, Scrip sends an event.completed or event.failed webhook event when processing finishes. This lets your application react to processing results without polling. Transient failures (infrastructure errors, timeouts, and program or group state that keeps changing across three attempts) retry automatically with exponential backoff (2s, 4s, 8s, 16s, 32s), up to 5 retries. Validation failures are terminal; fix the cause and retry the event by its id:
The response says how many events went back to PENDING:
A manual retry resets the retry count and gives the event a fresh set of attempts. Only a FAILED event can be retried; any other event is listed in skipped with code event_not_retryable. Name up to 250 events in one request; repeated IDs count once. A retried event runs every rule again against the participant’s current state. See Failure is all-or-nothing.

Failures by cause

To inspect open event failures grouped by error_code, call List failure causes:
To list the specific events that failed with a given code, filter GET /v1/events by first_error_code:
Once you resolve the underlying cause (for example, reactivating a suspended program or participant), you can retry all matching open failures in bulk by passing program_id, error_code, and a before timestamp instead of event_ids:
Each request queues up to 250 failed events and returns has_more and next_cursor if more remain. See Retry failed events for details.

Reversing an event

When a purchase is refunded, the value its event earned has to come back. If your rewards are a rate on the purchase amount, a return rule takes it back without looking up the original event. Reverse the event when a refund must take back exactly what it credited. A refund, chargeback, or void is your event, and the reversal is Scrip’s operation on the original event. Because the ledger records exactly what each event credited, Scrip can reverse it directly:
Omit fraction to reverse all remaining value. A new reversal returns 201 Created. Sending the same idempotency_key again returns the same reversal with Idempotent-Replayed: true. Say the event credited 100 points and only 30 of them are left in the lots it created. Half of the award is 50, so Scrip recovers 30 and reports 20 as shortfall:
The contract:
  • Recovery targets the original awards. Scrip claws back from the lots each award created, where the originally credited participant still holds that value. Value already spent, expired, transferred to someone else, or currently held is reported as shortfall_amount and never forced; a reversal cannot overdraw a balance.
  • Cumulative reversals are capped. Repeated partial reversals of one event cannot exceed what it originally awarded. A request over the remaining reversible value returns 409 reversal_exceeds_remaining instead of clamping.
  • The original event’s record never changes. Reversals post their own journal entries and return recovered value to the account each award drew from (the program wallet for prefunded assets). The impact endpoint shows the original event exactly as it ran.
  • State is reported, not reverted. The response includes the event’s counter, tag, and tier changes so you can decide what a refund means for them; send a compensating event if your policy requires it. Whether a refund erases a visit, and how partial refunds split across awards, are business decisions the endpoint deliberately leaves to you.
  • Plain rule-issued credits are reversible. Credit entries the reversal cannot process, such as settlement reconciliation entries, are listed in the response as ineligible_entries with reasons.
An event.reversed webhook event fires with the per-award accounting, and each line that recovered value fires one balance.reversed. When refund policy differs per award rather than scaling uniformly, compute the amounts in your backend and use the exact clawback pattern instead. Every event you read with get, list, or impact carries a reversal summary. Its status is NONE before any reversal, PARTIAL while some value is still reversible, and FULL once the reversals recovered every reversible award in full. last_reversed_at is the time of the latest reversal. To read each reversal with its lines and who made it, read the event with its reversals:

Idempotency

On POST /v1/events, the idempotency_key is the event’s identity. If you send the same program_id and idempotency_key more than once, Scrip processes the event once and every repeat gets the same event back with 202. You can send the key in the Idempotency-Key header instead of the body. If you send both and they differ, Scrip returns 400 header_body_mismatch. Events never return Idempotent-Replayed. Other requests can replay their first response. See API conventions for the routes and retention periods. If a network timeout occurs, re-send the same request. The duplicate is safely deduplicated. Treat idempotency keys as unique identifiers per intent. If the payload needs to change (for example, to correct an amount), use a new key.

A known key with a different payload

Sending a known key with a different payload does not replace the event. Scrip keeps the original event, still answers 202, and sends an event.rejected webhook event so you can see that your system sent two versions under one key. Subscribe to event.rejected if your integration can retry with changed data, then send the corrected event under a new key.
Use meaningful, deterministic idempotency keys like order-12345-completed or referral-user456-signup. Avoid random UUIDs, which defeat the purpose of deduplication.
You can also look up an event by its key:

Event data design

The event_data payload becomes the event variable in CEL expressions, and the event’s event_type becomes event.type. Send the name beside event_data, never inside it; a request with a type key in event_data is refused. Design the payload with rules in mind:
Rules reference event_data fields directly as event.amount, event.category, etc. If a rule references a field that isn’t in the payload, the condition evaluates to false and the rule doesn’t match. Use has() for fields that only appear on some events. See CEL expressions.

Batch ingestion

Send up to 100 events in a single request:
Each event is accepted, validated, and processed on its own; a batch is never all-or-nothing. The response is 202 with one entry in results per event, in the order you sent them. Each entry has the event’s index in your request and a status:
Valid events proceed even when others in the batch fail. A 400 is returned only when the request as a whole is malformed (zero events, more than 100, or unparseable JSON). Business validation errors surface later as event.failed webhook events.

Event routing

Conditions always read the event’s participant, and actions apply to that participant unless they name a target. To credit someone else, such as a referrer, send their id in event_data, as in "referrer_id": "user_456", and point the action at it with "target": {"external_id": "${{ event.referrer_id }}"}. The target participant must already exist and be enrolled in the program. To name a second participant on the event itself, such as a gift recipient, use recipient_external_id; see Sending an event. Targeting covers static and dynamic targets with complete rules.

Writing rules

Event-start snapshot evaluation.

Rule sets

Evaluation order and set-local stopping.

Webhooks

event.completed and event.failed.