Skip to main content

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.

This guide will help you set up a basic “Purchase Reward” program. By the end, you’ll have sent an event and seen a user’s balance increase automatically.

1. Set up your environment

Grab your API key from the Scrip dashboard and set it as an environment variable:
export SCRIP_API_KEY="sk_your_api_key"

2. Create your Program & Asset

A Program is the top-level container for your rules and participants. An Asset is the unit of value you’re tracking (points, credits, etc.). First create a program, then create an asset inside it.
# Create the Program
curl -X POST https://api.scrip.dev/v1/programs \
  -H "Authorization: Bearer $SCRIP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Customer Loyalty"}'
Copy the program_id from the response. You’ll use it in every subsequent call.
# Create a 'Points' asset inside that program
curl -X POST https://api.scrip.dev/v1/assets \
  -H "Authorization: Bearer $SCRIP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "program_id": "YOUR_PROGRAM_ID",
    "name": "Points",
    "symbol": "PTS",
    "inventory_mode": "SIMPLE",
    "issuance_policy": "UNLIMITED",
    "scale": 0
  }'
scale controls decimal precision. 0 means whole numbers only (10 points, not 10.5). Copy the asset_id from this response for the next step.

3. Define a Rule

Rules tell Scrip when to give out points. We’ll create a rule that gives 10 points for every event where the type is "purchase".
curl -X POST https://api.scrip.dev/v1/rules \
  -H "Authorization: Bearer $SCRIP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "program_id": "YOUR_PROGRAM_ID",
    "name": "10 Points per Purchase",
    "condition": "event.type == \"purchase\"",
    "actions": [
      {
        "type": "CREDIT",
        "asset_id": "YOUR_ASSET_ID",
        "amount": "10"
      }
    ]
  }'

4. Send an Event

Send a purchase event for a user. The external_id is whatever ID you use for this user in your own system. You don’t need to create the participant first. Scrip creates and enrolls them automatically when their first event arrives.
curl -X POST https://api.scrip.dev/v1/events \
  -H "Authorization: Bearer $SCRIP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "program_id": "YOUR_PROGRAM_ID",
    "external_id": "user_123",
    "idempotency_key": "first-purchase-001",
    "event_data": {
      "type": "purchase",
      "amount": 49.99
    }
  }'
The idempotency_key prevents duplicate processing. If you retry this request with the same key, Scrip returns the original response instead of crediting points again.

5. Verify the Balance

Events process asynchronously, so give it a moment. Then check user_123’s balance. First, look up the participant by their external_id to get the Scrip-assigned id:
curl https://api.scrip.dev/v1/participants?external_id=user_123 \
  -H "Authorization: Bearer $SCRIP_API_KEY"
Then use that id to fetch their balances:
curl https://api.scrip.dev/v1/participants/PARTICIPANT_UUID/balances \
  -H "Authorization: Bearer $SCRIP_API_KEY"
You should see 10 points. The rule matched the purchase event, credited the participant, and recorded the transaction in the ledger.

Next Steps

Now that you’ve seen the core loop, dive deeper:
  • Writing Rules: Use CEL to build complex logic (e.g., “double points for VIPs”).
  • State Management: Use counters and tags to track user progress over time.
  • Redemptions: Let users spend those points on rewards.