Rules

Simulate a rule

Dry-run a rule against sample event data. No ledger changes occur.

post/v1/rules/{rule_id}/simulate

Request

  • Base URL: https://api.scrip.dev
  • URL: https://api.scrip.dev/v1/rules/{rule_id}/simulate
  • Auth: HTTP bearer

Path parameters

rule_idstring uuid required

The rule's id.

Request body

diagnosticsboolean

Diagnostics opts into clause values, missing paths, short-circuit decisions, active-window and reachability outcomes. The normal response remains compact.

eventobject

Sample event data to evaluate against the rule. Numbers with a magnitude greater than 2^53 are rejected to prevent loss of precision. Supply exactly one of event or event_id.

event_idstring uuid

ID of a stored event to test. Uses its original data and timestamp, and the rule version recorded for that event when available.

event_timestampstring date-time

When the sample event occurred. Used to check whether it falls within the rule's active window. Cannot be used with event_id, which uses the stored timestamp.

participant_idstring uuid

A real participant whose current tags, counters, attributes and tiers Scrip loads as the simulation's participant context, the same fields a live rule sees. Send this or participant_state, not both. The simulation reads state and writes nothing.

participant_stateobject

Simulated participant state (tags, counters, attributes). Conditions read it as participant.counter.<name>, participant.tag.<name> and participant.attribute.<name>, which fall back to safe defaults, or with get(participant.counters, ...). Counter values can be JSON numbers or decimal strings, and Scrip evaluates both as numbers. Send this or participant_id, not both.

Example request

{
  "diagnostics": true,
  "event": {
    "amount": 75,
    "type": "purchase"
  },
  "event_id": "e5dc1b6a-7f3d-4e2a-8c1b-9a0f4d7e6c05",
  "event_timestamp": "2027-01-15T10:30:00Z",
  "participant_id": "f7a8b9c0-1d2e-4f3a-b4c5-d6e7f8a9b006",
  "participant_state": {
    "attributes": {
      "region": "US"
    },
    "counters": {
      "purchase_count": 9
    },
    "tags": [
      "vip"
    ]
  }
}

Response

Simulation result

Example response

{
  "evaluation": {
    "matched": true,
    "reason": "no such key: amount",
    "results": [
      {
        "action": {
          "amount": "${{ event.amount * 10 }}",
          "asset_id": "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02",
          "type": "CREDIT"
        },
        "result": {
          "amount": "750",
          "asset_symbol": "POINTS",
          "description": "Credit 750 POINTS to participant",
          "to_bucket": "AVAILABLE"
        }
      }
    ],
    "status": "EVALUATED"
  },
  "rule": {
    "condition": "event.type == 'purchase' && event.amount > 0",
    "id": "c9f0f895-fb98-4b39-9f86-1e5a0d3e2b03",
    "name": "Purchase Reward",
    "order": 1
  },
  "warnings": [
    {
      "code": "unknown_state_key",
      "key": "purchaseCnt",
      "kind": "counter",
      "message": "unknown counter \"purchaseCnt\" on participant: no rule in this program writes it; did you mean \"purchase_count\"?",
      "scope": "participant",
      "suggestion": "purchase_count"
    }
  ]
}

Changes

No recorded changes to this operation across all 1 revision of this API.