Skip to main content
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. Setup 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 your container, and an Asset is what you’re tracking (points, credits, etc.). Let’s create a Program called “Loyalty” and a “Points” asset in one go.
# 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"}'

# Save the program_id from the response. 
# Now, create a 'Points' asset (PTS) 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
  }'

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. Trigger the Reward

Now for the fun part. Send an event for a user (user_123). Note: You don’t need to create the user first—Scrip will automatically create and enroll them when the 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_timestamp": "2025-01-15T10:30:00Z",
    "event_data": {
      "type": "purchase",
      "amount": 49.99
    }
  }'

5. Verify the Balance

Wait a second for the async engine to finish, then check user_123’s balance. First, look up the participant by external ID to get their Scrip UUID:
curl https://api.scrip.dev/v1/participants?external_id=user_123 \
  -H "Authorization: Bearer $SCRIP_API_KEY"
Then use the id from the response to fetch their balance:
curl https://api.scrip.dev/v1/participants/PARTICIPANT_UUID/balances \
  -H "Authorization: Bearer $SCRIP_API_KEY"

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.