Skip to main content
A program’s rule configuration is every rule set and non-archived rule Scrip will evaluate: order, status, actions, and budgets. Its version number, rule_configuration_version, increases by one on every change. Writing rules covers creating and updating one rule at a time. Use this page when more than one writer can change the same program, or when one change touches several rules or sets. The dashboard and the Scrip MCP server, which lets AI clients work with your programs, follow the same flow.

Choose an endpoint

Create and patch on a single rule or set do not check rule_configuration_version, so two writers can overwrite each other. They still return the new version when the write changes the configuration. Place rules and sets with position, and read their resulting rank in order.

Read the current configuration

The response is the whole configuration at one version: every rule set in execution order, and every ACTIVE and SUSPENDED rule in each set. Archived rules are omitted.
Send this number back on every move, reorder, preview, and rollback request. Moves, reorders, and rollbacks take it as expected_rule_configuration_version. A preview takes it as base_rule_configuration_version. If another writer changes the program first, those requests return 409 rule_configuration_version_conflict. Read the configuration again and rebuild the request from the new configuration. Leave rule_set_id and order out when you rebuild a request from this response: a preview request that includes either returns 400 validation_error. See Get the complete rule configuration.

Move or reorder

To place one rule or set, send a position object. Its placement is first, last, before, or after, and before and after also need a reference_id. See Rule sets for execution order. Each example below starts from the configuration above, at version 12. Each returns 200 with the renumbered order and the new rule_configuration_version, 13. Send that number on your next write. Move one set. This puts tracking before default:
The response lists every set in its new order:
Replace the full set order when you already have the sequence you want. The list must contain every current rule set exactly once. This request gives the same result as the move above:
Reorder the ACTIVE and SUSPENDED rules in one set the same way. Include every non-archived rule in that set exactly once. An empty rule_ids list is valid for an empty set. This request puts Dining bonus first in default:
Move a rule inside its set, or into another set, in one request. This request moves Dining bonus into the empty tracking set:
The response shows the moved rule and the renumbered rules in both sets:

Check a draft

Single-rule validation and simulation evaluate one rule. They do not run the rest of the program, so they cannot prove cross-set order, stop_after_match, or conditions that depend on an earlier rule’s writes. Analyze the draft and simulate it before you apply a change that spans several rules. Send {} to analyze the live configuration:
To analyze a draft, send it as proposed_configuration, in the same shape as a preview. The response lists findings. Each finding has these fields:
Analysis can miss problems, and it can flag rules that work as you intend. Treat a likely or advisory finding as a reason to inspect and test the draft.
See Analyze a rule configuration. Then send the same draft as rule_configuration to POST /v1/programs/{program_id}/rule-configuration/simulations. The simulation shows the results without changing live rules, balances, budgets, or participant state. Test a full configuration covers testing with sample events or past events, comparing a draft with the live rules (compare_live), and reading each event’s rule trace. The multi-set example shows a layout where set-local stops and the event-start snapshot matter.

Preview and apply

Use preview and apply when one change updates several rule sets, rules, positions, statuses, actions, budgets, or field definitions. The preview body is the configuration you want, in execution order. This one starts from the configuration read above, at version 12, and adds a suspended Summer bonus rule to default:
Preview runs the same CEL, action, target, asset, and budget checks as a single-rule write. It does not change the live configuration or increment the version.

Event field and state definitions

field_definitions is optional. It annotates an event field, and a rule can read any event.* field without one. Add state_definitions for any new counter or tag a new or changed rule writes:
  • field_definitions: Specify event_type (the event name the definition applies to, matched against event.type), path (such as event.amount), label, and type (text, number, dollars, cents, bool, datetime, or enum with values).
  • state_definitions: Specify scope (participant, group, or program), kind (counter or tag), key, label, and unit (number, dollars, or cents for counters). A counter can also take a window for a rolling total; see Counter windows. A definition can carry display fields too; see Display fields.
  • Definitions are additive across your organization; omitting existing definitions from a preview request leaves them saved.
The preview response includes: A rule that reads an event field no recent event carries gets an event_field_not_received warning. The warning compares the rule with the program’s externally sent events from the last 7 days, up to 50. When the condition checks event.type against a literal name, the comparison uses events of that name and the warning carries event_type. Preview returns it with the rule’s rule_id and client_ref.
The warning does not stop a preview or an apply. It is absent when the sample has no events of that name, so an event name with no sampled events stays silent. Creating, updating, or validating a rule returns the same warning. Read the plan, diff, and warnings. Then apply exactly what preview stored:
The apply body cannot change the proposal. Scrip saves the definitions and applies the whole plan together, or saves neither. It refuses the apply if the token has expired, the hash does not match, or the configuration or something its rules refer to changed after the preview. A successful apply returns 200 with a change_id and the new rule_configuration, whose rule_configuration_version is one higher, 13 here. A preview can be applied once. If it expires, was already applied, or no longer matches the live configuration, create a new preview. See Preview a rule-configuration change set and Apply a rule-configuration change set.

History

Each change that takes effect creates one revision. A revision stores the configuration at that version and the diff from the previous one. List revisions, newest first:
Use pagination.next_cursor for the next page. Get one revision:
The revision list returns earliest_tracked_version, the oldest version you can read. History responses also carry caveats. When earliest_tracked_version is later than 1, they include pre_history_legacy_data, and Scrip does not show the versions before it. When the program has no revision yet, they include history_not_yet_tracked.

Roll back

Rollback builds a normal preview that restores a past configuration. History is left in place; the restore is a new revision.
The response has the same shape as a preview. Review the plan, the diff of what the rollback changes, and the warnings. Apply it with the same preview_token and request_hash as any other preview. Rule sets created after the target revision remain, with no rules, because rule sets cannot be deleted. The preview warns about each of those sets. Rules created after the target are archived. Rules archived since the target come back with their original IDs. Existing rule and rule-set IDs stay the same. The new revision records source_revision, so you can see which version was restored and who applied it. See Preview a rule-configuration rollback.

If a request fails

Testing

Prove a draft with analysis and simulations before you apply.

Writing rules

Create or patch one rule, including validation and simulation.

Rule sets

Execution order and set-local stop_after_match.