Rule structure
${{ }} wrapper marks a value as a CEL expression (see Rule actions).
Conditions
Conditions are written in CEL (Common Expression Language), a simple expression language for evaluating boolean conditions against event data and participant state.event.type is the event_type you send with the event, its name, such as purchase. Every other event.* field comes from event_data.
See CEL expressions for the full reference, including available variables, helper functions, and common patterns.
Rule sets
Every rule belongs to a rule set. Every program starts with a set whosekey is default, and rule writes that omit rule_set_id go there.
To place a rule when creating it, use position (first, last, or before/after with a reference_id). Omit it to append. Scrip returns the rule’s resulting rank in order.
stop_after_match: true skips later rules in this rule’s set after a successful match. Other sets continue. A budget skip does not trigger the stop. Rule sets covers how that stop interacts with set order.
See Managing rule configuration for consistent reads, moves, preview and apply, history, and rollback.
Time-windowed rules
Useactive_from and active_to to schedule rules for specific periods. Outside the window, the rule is skipped during evaluation.
Time windows are checked against the event’s event_timestamp, the same value CEL sees as now, not the wall-clock time at processing. active_from is inclusive and active_to is exclusive. A matching rule outside its window is recorded as a skipped evaluation with reason OUTSIDE_TIME_WINDOW.
- A delayed event, a retry, and a replay in a rule configuration simulation all read the same
event_timestamp, so they get the same window decision. If you change the rule’s window before the event processes, the new window applies. - Event timestamps are supplied by the caller, so a backdated event (a historical import, for example) can land inside a window that has already closed on the calendar and still fire the rule.
event_timestamp fire both rules and earn 2x total. Events stamped January 1st or later skip the promo rule (active_to is exclusive) and the base rule continues on its own. Campaigns covers how windowed rules stack on or override the base rate, and how to cap and test them.
Budgets
Budgets cap how much of an asset a rule can issue. When a credit would go over a budget, the rule still matches but all of its actions are skipped for that evaluation. Each budget has ascope that sets who the limit applies to:
A rule can have one budget per asset and scope, so one asset can carry a program-wide pool and a per-participant cap at the same time, each with its own
limit and schedule. Budgets are defined inline on the rule:
A duration is a number and a unit, such as
90d, and you can combine units, as in 36h30m. Use w for weeks, d for days, h for hours, m for minutes, and s for seconds. m always means minutes. Months and years are not supported, so write 90d for about three months. See Durations.
A budget caps an amount of an asset. To cap how many times a rule pays, such as a bonus on each participant’s first three purchases a day, gate the rule on a counter instead:
Schedule types
A lifetime cap omitsschedule_type:
CRON resets on a calendar schedule evaluated in UTC, regardless of when the rule was created. Expressions cannot include a timezone. A PARTICIPANT budget resets every participant on the same clock. This one resets everyone’s cap at midnight UTC:
INTERVAL resets after a fixed duration. A program-wide budget’s window starts when the budget is saved and restarts after each reset. A PARTICIPANT budget gives each participant their own window, starting at their first credit from the rule. After a participant’s window ends, their next credit starts a new one:
Who a per-participant budget counts
APARTICIPANT budget counts each CREDIT of its asset against the participant who receives it:
A
PARTICIPANT budget requires at least one CREDIT of that asset to a participant in the same rule.
When a budget runs out
Each credit is checked against the rule’s budgets on that asset before it is issued. A credit can bring the total exactly to the limit. Scrip does not shrink a credit to fit what is left. If a credit would take the rule’s total (PROGRAM) or its recipient’s total (PARTICIPANT) past the limit, all of the rule’s actions roll back. Evaluation continues with the next rule in the set and then with later sets. A budget skip does not trigger stop_after_match.
Scrip checks credits against a budget one at a time. Events that reach the rule at the same moment, for the same participant or for different ones, cannot take it past its limit.
Budget periods follow the time Scrip processes the credit, not the event’s event_timestamp. A delayed or backdated event counts in the period in which it is processed.
The skip is recorded in the event’s rule_evaluations, returned by GET /v1/events/{event_id}, with status SKIPPED and a reason:
resets clause for a lifetime budget, or when the recipient has no open window, such as a first credit larger than the limit. When a rule has both scopes on one asset, a skip by either budget rolls back the whole rule, so the program-wide total counts only credits that were issued.
The response for any rule includes each budget’s scope. Program-wide budgets also report consumed and, when scheduled, next_reset_at. Per-participant budgets omit both because usage differs for each participant:
Resetting a budget
Scheduled budgets reset on their own. A signed-in team member who can manage rules can reset a rule’s program-wide budget early, for example through the Scrip MCP server. API keys cannot reset a budget, and aPARTICIPANT budget has no early reset.
To let a capped participant earn more, raise the PARTICIPANT budget’s limit, which applies to every participant, or credit that participant with an ADJUST balance operation, which does not count against rule budgets. To restart a program-wide pool from the API, change the budget’s schedule, which restarts its usage.
Updating budgets
Budgets are updated as part of the rule. Include the fullbudgets array in your update request and it replaces the previous one. Omitting the field leaves budgets unchanged.
limit keeps its current usage and applies immediately. Changing its schedule restarts usage: the program-wide total, or every participant’s usage for a PARTICIPANT budget.
To remove all budgets from a rule, send an empty array:
State snapshot evaluation
Scrip takes one snapshot of participant, group, and program state when processing of an event starts. Every rule condition and every action expression in that event reads the snapshot, not live state. The snapshot covers counters, tags, attributes, tiers, and balances, and every rule set shares it. Action expressions include asset action amounts,COUNTER and SET_ATTRIBUTE values, reference_id, expiration and maturity dates, and dynamic target expressions.
Scrip saves each rule’s changes in rule-set and rule order. If one rule increments a counter, adds a tag, sets an attribute, or assigns a tier, a later rule in the same event still sees the old value. The next event sees the change.
For shared program and group state, Scrip can refresh a key if another request changed it before a state action updates it. The snapshot then uses the value found before this event’s update. See Shared program and group state.
Example
spend is 900 and event.amount is 200:
- Rule 1 executes and saves the counter as 1100
- Rule 2 evaluates against the snapshot value (900), so it does not match
TAG action that adds vip, a Rule B condition that checks "vip" in participant.tags still evaluates against the pre-event tag set. The tag is visible on the next event.
Threshold crossing pattern
To detect when a counter crosses a threshold during an event, check the pre-event value plus the event amount:SCHEDULE_EVENT).
See CEL Expressions for more patterns including milestones, date ranges, and capped bonuses.
Rule status
Updating rules under live traffic
Scrip evaluates each event against the rule definitions that are live when processing starts, not when you submitted the event. This matters when you change a rule (its condition, actions, amount, containing set, order, or status) while events are still in flight:- Events already processed keep the result from the previous definition.
- Events not yet processed use the new definition.
- A batch that spans your change can split across both versions.
rule_set_id the rule was in when it ran and a rule_history_id that links to the exact rule version active when the event was evaluated:
rule_configuration_version back: as expected_rule_configuration_version on moves and rollback, and as base_rule_configuration_version on a preview. A stale version returns 409 rule_configuration_version_conflict. See Managing rule configuration.
If you need every event in a batch to use a single definition, stop submitting affected events and wait until in-flight events finish before you make the change.
Validation and simulation
Save-time validation
Creating or updating a rule validates both thecondition and every action expression:
- Syntax and field checks: Template syntax errors, CEL compile errors, and references to unknown participant fields, tier keys, or unlinked asset symbols return
400 validation_error. LOT-only fields:reference_id,expires_in/expires_at, andmatures_in/matures_atrequire aLOT-mode asset and are rejected onSIMPLEassets.- No
${{ }}oncondition: Theconditionfield is always evaluated as CEL; only action fields use the${{ }}wrapper. - Non-blocking
warnings: Responses also include awarningsarray for issues that don’t block saving (such as aSET_ATTRIBUTEvalue that looks like an unmarked expression, or anevent_field_not_receivedwarning for an event field no recent event carries).
Validate a condition
Check a condition, and optionally draft actions, before creating a rule:program_id to check tier keys and asset symbols against that program’s configuration and receive vocabulary warnings, and an optional actions array to run the same save-time checks on draft actions. A misspelled event.* field saves fine and then never matches. With a program_id, the response carries an event_field_not_received warning when none of the program’s recent events has the field; Managing rule configuration describes it.
Simulate a rule
Test a rule against sample data without saving any changes:participant_state field is optional. The response includes whether the condition matched and, for each action, the evaluated result (resolved amounts, projected counter values, etc.).
Asset action results also show where the value would go, with the fields that apply to each action: from_bucket, to_bucket, and the resolved reference_id. For example, a CREDIT result has to_bucket but no from_bucket, and a DEBIT result has only from_bucket. Simulate a rule lists the fields for each action type. A CREDIT result shows expires_at and matures_at as full timestamps, including fractional seconds. A duration such as 30d counts from the time of your request, so a live run of the rule computes a later timestamp.
A CREDIT with a reference_id and bucket left at AVAILABLE is a settlement, and its result shows "settles_reference": true. The flag does not mean pending rewards exist for that reference. When the rule runs, the CREDIT settles the pending rewards for the reference, or credits the full amount if there are none.
Simulation uses participant balances to evaluate the condition and any action expression that reads them. The actions do not run against the ledger or look at lots, so a result does not show whether pending rewards exist or which lots an action would use. A rule configuration simulation shows that.
To simulate against a real participant’s current state instead of mocking it, pass participant_id (mutually exclusive with participant_state):
missing_participant_context warning and the condition evaluates against empty defaults.
Counter values in participant_state may be JSON numbers or decimal strings (the format the participant detail returns), so you can paste a counters map from a real state read directly into a simulation request.
Simulation does not execute SCHEDULE_EVENT or BROADCAST actions, but it does resolve their event_data templates: the action result shows the resolved event_data the action would emit, or an error when a template fails. Any action whose target names a recipient also shows who it would reach in resolved_target. See Targeting.
Simulation applies the same limits as a live event: asset action amounts must resolve to positive values (zero or negative amounts fail in the action result), and event numbers or amount results above 2^53 are rejected. A simulation shows how one rule behaves. It does not prove ordering or stop behavior across several rules and sets. See Test a full configuration.
Simulate a draft rule
To test a rule before saving it, usePOST /v1/rules/simulate with a program_id and a rule object (name, condition, actions) plus an event and its event_type, or the event_id of a stored event to test the draft on that event’s data, and the same participant_id or participant_state fields. The draft goes through the same validation as creating a rule, without saving anything.
CEL expressions
Condition syntax, variables, helper functions, and calendar comparisons.
Rule actions
Every action type, field, dynamic expression, and targeting option.
Rule sets
Control execution priority and set-local
stop_after_match behavior.