intermediate
Automate Ticket Routing with Rules
Set up automation rules that auto-assign urgent tickets, tag billing issues, and send notifications, all via the API.
Prerequisites
- A cStar account with a secret API key
1
Create an auto-assign rule
Automatically assign urgent tickets to a specific agent when they come in.
js
const rule = await cstar.automations.create({
name: 'Auto-assign urgent tickets',
triggerEvent: 'ticket.created',
conditions: {
all: [{ field: 'priority', operator: 'is', value: 'urgent' }],
any: [],
},
actions: [
// memberId is the teammate's user ID
{ type: 'assign_to', memberId: 'your-best-agent-user-id' },
{ type: 'add_tags', tags: ['auto-assigned', 'urgent'] },
{ type: 'send_notification', to: 'assigned_agent', message: 'Urgent ticket auto-assigned to you!' },
],
});
console.log('Rule created:', rule.id); 2
Add a billing tag rule
Auto-tag tickets that mention billing keywords.
js
await cstar.automations.create({
name: 'Tag billing tickets',
triggerEvent: 'ticket.created',
conditions: {
all: [],
any: [
{ field: 'title', operator: 'contains', value: 'billing' },
{ field: 'title', operator: 'contains', value: 'invoice' },
{ field: 'title', operator: 'contains', value: 'payment' },
{ field: 'title', operator: 'contains', value: 'refund' },
],
},
actions: [{ type: 'add_tags', tags: ['billing'] }],
}); 3
Test with a dry run
Verify your rules work without executing actions.
js
// Dry-run against an existing ticket (bare resource, Plan 03)
const result = await cstar.automations.test(rule.id, {
resourceType: 'ticket',
resourceId: 'tkt_abc123',
});
console.log('Would match:', result.wouldMatch);
console.log('Actions:', result.actionsWouldExecute); bash
# Or use the CLI
cstar automations test rule_abc --resource-type ticket --resource-id tkt_abc123