Rules
The Rules API allows you to create and manage rules for campaigns in advanced mode. Rules define the triggers, conditions, and effects that power your loyalty campaigns.
Overview
Base URL:
https://api.monterosa.cloud/loyalty/v1Authentication: Bearer token required
Org Context:
X-Monterosa-Org-IDheader required
Endpoints
List Rules
Get all rules for a specific campaign.
GET /v1/campaigns/{campaignId}/rulesPath Parameters:
campaignId(string, required) - Campaign ID
Response:
{
"success": true,
"data": {
"rules": [
{
"ruleId": "rule_123e4567-e89b-12d3-a456-426614174000",
"campaignId": "camp_123e4567-e89b-12d3-a456-426614174000",
"triggerType": "poll_vote",
"conditions": [
{
"field": "vote.option",
"operator": "equals",
"value": "TeamA"
}
],
"effects": [
{
"type": "award_points",
"params": {
"amount": 10
}
}
],
"priority": 5,
"enabled": true,
"createdAt": "2025-10-05T12:00:00.000Z",
"updatedAt": "2025-10-05T12:00:00.000Z"
}
]
}
}Create Rule
Create a new rule for a campaign (advanced mode only).
Path Parameters:
campaignId(string, required) - Campaign ID
Request Body:
Required Fields:
triggerType(string) - Type of trigger eventeffects(array) - At least one effect is required
Optional Fields:
conditions(array) - Conditions that must be metpriority(number) - Rule priority (default: 5)enabled(boolean) - Whether rule is active (default: true)
Response: 201 Created
Error Cases:
400- Campaign is in simple mode (cannot manually create rules)400- Missing required fields404- Campaign not found
Update Rule
Update an existing rule.
Path Parameters:
campaignId(string, required) - Campaign IDruleId(string, required) - Rule ID
Request Body:
Updatable Fields:
triggerTypeconditionseffectspriorityenabled
Response: 200 OK
Error Cases:
400- Empty request body400- Rule belongs to different campaign404- Rule not found
Delete Rule
Permanently delete a rule.
Path Parameters:
campaignId(string, required) - Campaign IDruleId(string, required) - Rule ID
Response: 204 No Content
Error Cases:
400- Rule belongs to different campaign404- Rule not found
Trigger Types
Supported trigger types:
poll_vote- User votes in a pollquiz_answer- User answers a quiz questionprediction_made- User makes a predictionmessage_sent- User sends a messagepage_view- User views a pagecustom_event- Custom event type
Effect Types
Supported effect types:
award_points- Award points to useraward_badge- Award a badgeupdate_tier- Update user tiersend_notification- Send notificationtrigger_webhook- Call external webhook
Conditions
Conditions support various operators:
equals- Exact matchnot_equals- Not equalgreater_than- Numeric comparisonless_than- Numeric comparisoncontains- String/array containsin- Value in arrayregex- Regular expression match
Testing Results
All Rules API endpoints tested and validated:
✅ 26/26 tests passing
✅ Average response time < 2s
✅ Full CRUD operations
✅ Validation and error handling
✅ Multi-tenant isolation
Notes
Rules can only be manually created for campaigns in advanced mode
Simple mode campaigns have auto-generated rules from trigger/effect definitions
Rules are executed in priority order (higher priority first)
Disabled rules are not executed
All timestamps in ISO 8601 format (UTC)
Last updated

