Rules

Simulate a draft rule

Dry-run a draft rule (not yet saved) against sample event data. The draft is validated exactly like rule create, then evaluated; nothing is persisted and no ledger changes occur.

post/v1/rules/simulate

Request

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

Request body

diagnosticsboolean

Include an explanation of each part of the CEL condition. Nothing is saved.

eventobject required

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

event_timestampstring date-time

When the sample event occurred. Used to check whether it falls within the rule's active window.

participant_idstring uuid

A real participant whose current tags, counters, attributes and tiers Scrip loads as the simulation's participant context. Send this or participant_state, not both.

participant_stateobject

Simulated participant state (tags, counters, attributes), with the same meaning as in POST /v1/rules/{rule_id}/simulate. Send this or participant_id, not both.

program_idstring uuid required

Program providing the validation and evaluation context (asset linkage, tier keys, participant state lookups)

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.