> ## Documentation Index
> Fetch the complete documentation index at: https://docs.scrip.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Start with https://docs.scrip.dev/agents.md and https://docs.scrip.dev/which-endpoints-you-need.md. Your application only needs a few API calls as users earn and spend (`POST /v1/events`, balance/history reads, and redemptions); program setup happens in the dashboard or setup scripts.
> Use `https://api-sandbox.scrip.dev` with `sk_test_` keys for testing, and `https://api.scrip.dev` with `sk_live_` keys for production. Keep API keys on your server.
> Pass your own user ID as `external_id` on events and prefix it with `ext:` in participant URL paths (e.g., `GET /v1/participants/ext:user_123/balances`). By default (`on_unknown_participant: CREATE`), the first event for a new `external_id` creates and enrolls the participant automatically.
> Events process asynchronously: `POST /v1/events` returns `202 Accepted` when queued, and rules evaluate in the background. Pass an `idempotency_key` (such as an order ID) on every event, and wait for the `event.completed` webhook or poll `GET /v1/events/{event_id}` before reading updated balances.
> Connect the hosted MCP server at https://mcp.scrip.dev/mcp (OAuth, defaults to Sandbox) to inspect programs, validate and simulate rules, and trace events. Append `.md` to any docs URL for Markdown, or fetch https://docs.scrip.dev/openapi.json for full endpoint schemas.

# Campaigns

> Run limited-time promotions that stack on or override your base earn rules

A campaign changes what participants earn for a limited time, such as double points for a month or a higher rate on dining. Campaigns are not a separate API resource: build them from rules with `active_from` and `active_to` windows, cap spend with budgets, and launch or roll them back as a unit through rule configuration.

For window and budget mechanics on a single rule, see [Time-windowed rules](https://docs.scrip.dev/guides/writing-rules.md#time-windowed-rules) and [Budgets](https://docs.scrip.dev/guides/writing-rules.md#budgets).

## Choose how the bonus applies

| You want | Where the campaign rules go | Why |
| - | - | - |
| Bonus on top of the base rate (stack) | Their own set, positioned after your earning set | Every set with a matching rule runs, so the base rate and the bonus both pay |
| Replace the base rate for the window (override) | The same set as the base rate, positioned first, with `stop_after_match: true` | A match stops the rest of that set, so the base rule is skipped while the window is open |
| Reward a new behavior only during the window | Their own set | Nothing to interact with |

Stacking is the safer default. Override only when the campaign rate is meant to replace the whole rate.

## Stack a bonus

Add a `campaigns` set after your earning set (returning ID `d4735e3a-265e-4f16-b1a5-4c8e9d6f0a09` here), then add windowed rules to it. This rule adds 2% on dining for October:

```bash theme={null}
POST /v1/programs/{program_id}/rule-sets
```

```json theme={null}
{"key": "campaigns", "name": "Campaigns"}
```

```bash theme={null}
POST /v1/rules
```

```json theme={null}
{
  "program_id": "8f14e45f-ceea-4e70-9df8-2a7d1b3c9f01",
  "rule_set_id": "d4735e3a-265e-4f16-b1a5-4c8e9d6f0a09",
  "name": "october_dining_bonus",
  "active_from": "2027-10-01T00:00:00Z",
  "active_to": "2027-11-01T00:00:00Z",
  "condition": "event.type == 'purchase' && event.mcc in ['5812', '5813', '5814']",
  "actions": [
    {
      "type": "CREDIT",
      "asset_id": "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02",
      "amount": "${{ event.amount * 0.02 }}",
      "description": "October dining bonus"
    }
  ]
}
```

A dining purchase stamped in October earns the base rate from the earning set plus 2% from this rule. Stamped in November, the rule is skipped (`OUTSIDE_TIME_WINDOW`) and the base rate pays alone.

## Override the base rate

To pay a flat 5% on everything during launch week instead of the usual rates, put the rule first in the earning set with `stop_after_match: true`:

```bash theme={null}
POST /v1/rules
```

```json theme={null}
{
  "program_id": "8f14e45f-ceea-4e70-9df8-2a7d1b3c9f01",
  "rule_set_id": "d4735e3a-265e-4f16-b1a5-4c8e9d6f0a06",
  "position": {"placement": "first"},
  "stop_after_match": true,
  "name": "launch_week_5pct",
  "active_from": "2027-10-01T00:00:00Z",
  "active_to": "2027-10-08T00:00:00Z",
  "condition": "event.type == 'purchase'",
  "actions": [
    {
      "type": "CREDIT",
      "asset_id": "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02",
      "amount": "${{ event.amount * 0.05 }}",
      "description": "Launch week 5%"
    }
  ]
}
```

Inside the window, a purchase matches this rule and skips the rest of the earning set. Outside the window, the rule is skipped and the base rules run as usual. Rules in other sets still run either way; see [Set-local stopping](https://docs.scrip.dev/guides/rule-sets.md#set-local-stopping).

## Windows and backdated events

`active_from` (inclusive) and `active_to` (exclusive) compare against each event's `event_timestamp`, not processing time. You can schedule campaign rules weeks ahead, and retries make the same decision as the original run. Keep in mind that backdated historical imports can still match a closed campaign window unless you suspend or archive the rules first.

## Cap the spend

Combine a program-wide budget (total campaign pool) with a per-participant budget (`scope: "PARTICIPANT"`) to cap both total spend and per-person earnings. This rule pays 5% on purchases up to 250,000 in total and at most 2,000 per participant:

```bash theme={null}
POST /v1/rules
```

```json theme={null}
{
  "program_id": "8f14e45f-ceea-4e70-9df8-2a7d1b3c9f01",
  "rule_set_id": "d4735e3a-265e-4f16-b1a5-4c8e9d6f0a09",
  "name": "october_5pct_capped",
  "active_from": "2027-10-01T00:00:00Z",
  "active_to": "2027-11-01T00:00:00Z",
  "condition": "event.type == 'purchase'",
  "budgets": [
    {"asset_id": "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02", "limit": "250000"},
    {"asset_id": "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02", "scope": "PARTICIPANT", "limit": "2000"}
  ],
  "actions": [
    {"type": "CREDIT", "asset_id": "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02", "amount": "${{ event.amount * 0.05 }}", "description": "October 5% bonus"}
  ]
}
```

To limit a flat bonus to once per participant (instead of capping a cumulative amount), pair a `TAG` action with a condition guard such as `!('october_bonus_paid' in participant.tags)`; see [One-time welcome reward](https://docs.scrip.dev/examples/common-patterns.md#one-time-welcome-reward). Budgets and tag or counter guards work independently, so you can combine a program-wide pool with a one-time tag guard when capping how many people can claim a flat bonus.

Once a budget is exhausted, the campaign rule is skipped (`BUDGET_EXCEEDED` or `PARTICIPANT_BUDGET_EXCEEDED`) while base rules keep paying. For a campaign funded in its own currency with a hard balance ceiling, link a `PREFUNDED` asset and fund the program wallet instead; see [Issuance policy](https://docs.scrip.dev/guides/asset-configuration.md#issuance-policy).

## Test before launch

Send the campaign rules as a draft `rule_configuration` to `POST /v1/programs/{program_id}/rule-configuration/simulations` with `options.compare_live: true` to compare the draft against your live configuration without crediting live balances.

Because synthetic scenario events share one clock time, test window boundaries using `replay` mode over historical events on both sides of the window, or call [Simulate a draft rule](https://docs.scrip.dev/api-reference/rules/simulate-a-draft-rule.md) with explicit `event_timestamp` values inside and outside the window. See [Testing](https://docs.scrip.dev/guides/testing.md#test-a-full-configuration).

## Launch, monitor, and retire

Publish multi-rule campaigns in one atomic version using `/rule-configuration/preview` and `/rule-configuration/apply` (see [Managing rule configuration](https://docs.scrip.dev/guides/managing-rule-configuration.md)). Because windows control activation, you can apply the revision ahead of time.

| You want | Do |
| - | - |
| Stop a campaign early | Set the rule's `status` to `SUSPENDED`. Events not yet processed skip it immediately. |
| Change the rate | `PATCH` the rule; future events use the updated rate. |
| Check how much has been paid | Read the rule's program-wide budget `consumed` total. |
| Trace why an event did or did not qualify | Read the event's `rule_evaluations` for `OUTSIDE_TIME_WINDOW`, `BUDGET_EXCEEDED`, or `PARTICIPANT_BUDGET_EXCEEDED`. |
| Attribute campaign credits in finance reports | Name the campaign in each `CREDIT` action's `description` so it appears on statements and journal entries. |

After `active_to` passes, the window closes automatically. Archive the rules when you no longer need them in the active list, update their window to run the promotion again, or roll back to the pre-campaign revision.

> [card] [Time-windowed rules](https://docs.scrip.dev/guides/writing-rules.md#time-windowed-rules)
>
> Window fields, budgets, and live-traffic update behavior.

> [card] [Rule sets](https://docs.scrip.dev/guides/rule-sets.md)
>
> Set order, positions, and set-local stopping.

> [card] [Test a full configuration](https://docs.scrip.dev/guides/testing.md#test-a-full-configuration)
>
> Compare a draft campaign against live rules before launching.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.