Skip to main content
POST
/
v1
/
rules
Create a rule
curl --request POST \
  --url https://api.scrip.dev/v1/rules \
  --header 'Content-Type: application/json' \
  --header 'X-API-Key: <api-key>' \
  --data @- <<EOF
{
  "actions": [
    {
      "allow_negative": false,
      "amount": "10",
      "asset_id": "550e8400-e29b-41d4-a716-446655440000",
      "bucket": "AVAILABLE",
      "delay": "24h",
      "description": "Purchase reward",
      "event_name": "check_status",
      "expires_at": "8760h",
      "key": "purchase_count",
      "level": "gold",
      "matures_at": "720h",
      "payload": {},
      "reference_id": "event.authorization_id",
      "reset_after": "720h",
      "tag": "VIP",
      "target": {
        "external_id": "event.referrer_id",
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "participant_id": "event.recipient_id",
        "type": "PARTICIPANT"
      },
      "tier": "status",
      "type": "CREDIT",
      "value": "1"
    }
  ],
  "condition": "event.type == 'purchase'",
  "name": "Purchase Reward",
  "program_id": "550e8400-e29b-41d4-a716-446655440000",
  "active_from": "2024-01-01T00:00:00Z",
  "active_to": "2024-12-31T23:59:59Z",
  "budgets": [
    {
      "asset_id": "550e8400-e29b-41d4-a716-446655440000",
      "cron_expression": "0 0 1 * *",
      "interval": "720h",
      "limit": "10000.00",
      "schedule_type": "CRON"
    }
  ],
  "description": "Awards 10 points per dollar spent",
  "order": 100,
  "status": "ACTIVE",
  "stop_after_match": false
}
EOF
{
  "actions": [
    {
      "amount": "event.amount * 10",
      "asset_id": "550e8400-e29b-41d4-a716-446655440002",
      "type": "CREDIT"
    }
  ],
  "active_from": "2024-01-01T00:00:00Z",
  "active_to": "2024-12-31T23:59:59Z",
  "budgets": [
    {
      "asset_id": "550e8400-e29b-41d4-a716-446655440000",
      "consumed": "4500.00",
      "cron_expression": "0 0 1 * *",
      "interval": "720h",
      "limit": "10000.00",
      "next_reset_at": "2026-03-01T00:00:00Z",
      "schedule_type": "CRON"
    }
  ],
  "condition": "event.type == 'purchase' && event.amount > 0",
  "created_at": "2024-01-15T10:30:00Z",
  "deleted_at": "2023-11-07T05:31:56Z",
  "description": "Awards 10 points per dollar spent",
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "Purchase Reward",
  "order": 100,
  "program_id": "550e8400-e29b-41d4-a716-446655440001",
  "status": "ACTIVE",
  "stop_after_match": false,
  "updated_at": "2024-01-15T10:30:00Z"
}
Creates a rule within a program. A rule consists of a CEL condition that is evaluated against each incoming event and an actions array that executes when the condition matches. Common actions include crediting balances, incrementing counters, and setting tags. The order field controls evaluation priority: lower values are evaluated first. If order is omitted, it is auto-assigned to 10 above the current highest order in the program. No two active rules in the same program can share the same order value. When setting order manually, leave gaps between values (e.g. 10, 20, 30) so you can insert new rules between existing ones without reordering. Set stop_after_match to true if you want to prevent lower-priority rules from firing when this rule matches. active_from and active_to define an optional time window for the rule using RFC 3339 timestamps. Outside the window, the rule is skipped during evaluation. Time windows are checked against the current wall-clock time, not the event’s event_timestamp, so historical imports won’t trigger a rule whose window has already passed. Use these to layer promotional rules on top of permanent base rules. budgets cap how much a rule can issue per asset over a given period. Each budget specifies an asset_id, a limit, and an optional schedule_type (CRON or INTERVAL) that controls automatic resets. Omitting the schedule type creates a lifetime budget that never resets on its own. When a budget is exhausted, the rule still matches but the credit action is suppressed. You can manually reset a budget via the reset budget endpoint. A rule is created in ACTIVE status by default.
For usage patterns and examples, see the Writing Rules guide.

Authorizations

X-API-Key
string
header
required

API key passed in the X-API-Key header.

Body

application/json

Rule with CEL condition and actions array

Request body for creating a new rule with CEL condition and actions

actions
object[]
required

Actions to execute when the condition matches (must be non-empty). Each action has a type field that determines which other fields are relevant.

Minimum array length: 1
condition
string
required

CEL expression that determines when the rule fires

Minimum string length: 1
Example:

"event.type == 'purchase'"

name
string
required

Display name for the rule

Required string length: 1 - 255
Example:

"Purchase Reward"

program_id
string<uuid>
required

Program to attach this rule to

Example:

"550e8400-e29b-41d4-a716-446655440000"

active_from
string<date-time>

Start of the rule's active window (RFC 3339). Null means immediately active.

Example:

"2024-01-01T00:00:00Z"

active_to
string<date-time>

End of the rule's active window (RFC 3339). Null means no end date.

Example:

"2024-12-31T23:59:59Z"

budgets
object[]

Optional budget constraints for this rule. Omit or pass null for no budgets.

description
string

Human-readable summary of what this rule does

Maximum string length: 1000
Example:

"Awards 10 points per dollar spent"

order
integer

Evaluation sequence (lower = first). Auto-assigned if omitted.

Required range: x >= 1
Example:

100

status
enum<string>

Initial lifecycle status (ACTIVE or SUSPENDED). Defaults to ACTIVE.

Available options:
ACTIVE,
SUSPENDED
Example:

"ACTIVE"

stop_after_match
boolean

When true, no subsequent rules evaluate after this one matches

Example:

false

Response

Rule created

actions
object[]

Actions to execute when the condition matches

Example:
[
{
"amount": "event.amount * 10",
"asset_id": "550e8400-e29b-41d4-a716-446655440002",
"type": "CREDIT"
}
]
active_from
string<date-time>

Start of the rule's active window (RFC 3339, null if always active)

Example:

"2024-01-01T00:00:00Z"

active_to
string<date-time>

End of the rule's active window (RFC 3339, null if no end date)

Example:

"2024-12-31T23:59:59Z"

budgets
object[]

Budget constraints applied to this rule

condition
string

CEL expression that determines when the rule fires

Example:

"event.type == 'purchase' && event.amount > 0"

created_at
string<date-time>

When this rule was created (RFC 3339)

Example:

"2024-01-15T10:30:00Z"

deleted_at
string<date-time>

When this rule was archived (null if not archived)

description
string

Human-readable summary of what this rule does

Example:

"Awards 10 points per dollar spent"

id
string<uuid>

Unique identifier for this rule

Example:

"550e8400-e29b-41d4-a716-446655440000"

name
string

Display name

Example:

"Purchase Reward"

order
integer

Evaluation sequence (lower = first, must be unique per program)

Example:

100

program_id
string<uuid>

Program this rule belongs to

Example:

"550e8400-e29b-41d4-a716-446655440001"

status
string

Lifecycle status: ACTIVE, SUSPENDED, or ARCHIVED

Example:

"ACTIVE"

stop_after_match
boolean

When true, no subsequent rules evaluate after this one matches

Example:

false

updated_at
string<date-time>

When this rule was last modified (RFC 3339)

Example:

"2024-01-15T10:30:00Z"