Campaigns
Campaigns define how members are rewarded — points, tangible rewards, or both. A campaign has an earningRule (how to award), optional targeting (segments, stores, schedule), and an optional redemptionRule (how to burn). Only ACTIVE campaigns fire during evaluate().
State machine
DRAFT → ACTIVE → PAUSED → ACTIVE
ACTIVE → ARCHIVED (terminal)
Endpoints
/tenants/{tenantId}/campaignsList all campaigns. Filter by state: DRAFT · ACTIVE · PAUSED · ARCHIVED.
/tenants/{tenantId}/campaignsCreate a campaign. Starts in DRAFT state. Must be activated before it can fire.
/tenants/{tenantId}/campaigns/{campaignId}Get a campaign by ID including full earningRule and redemptionRule configuration.
/tenants/{tenantId}/campaigns/{campaignId}Update a campaign — name, rules, budget, schedule, or targeting. ACTIVE campaigns can be patched.
/tenants/{tenantId}/campaigns/{campaignId}Archive a campaign. Archived campaigns cannot be reactivated.
/tenants/{tenantId}/campaigns/{campaignId}/activateTransition a DRAFT campaign to ACTIVE. Required before evaluate() can match the campaign.
/tenants/{tenantId}/campaigns/{campaignId}/pausePause an active campaign. evaluate() will skip paused campaigns.
/tenants/{tenantId}/campaigns/{campaignId}/resumeResume a paused campaign.
Earning Rule Types
Set earningRule.type when creating a campaign. Each type has its own required fields.
Targeting
Campaigns can target specific audiences and stores:
Create a campaign
curl -X POST "https://loyalty-engine-production-e5cb.up.railway.app/v1/tenants/$TENANT_ID/campaigns" \
-H "X-API-Key: sk_test_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Spend & Earn",
"earningRule": {
"type": "SPEND_PERCENTAGE",
"percentage": 1
}
}'Activate it
curl -X POST "https://loyalty-engine-production-e5cb.up.railway.app/v1/tenants/$TENANT_ID/campaigns/$CAMPAIGN_ID/activate" \
-H "X-API-Key: sk_test_YOUR_KEY"Campaigns start in DRAFT state. Call /activate before testing with evaluate(). If your first evaluate() returns "campaigns": [], check the _debug field for why the campaign skipped.