Skip to main content
← All Guides
intermediate 10 min 200 XP

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.

const { data: rule } = await cstar.automations.create({
  name: 'Auto-assign urgent tickets',
  triggerEvent: 'ticket.created',
  conditions: {
    all: [{ field: 'priority', operator: 'equals', value: 'urgent' }],
    any: [],
  },
  actions: [
    { type: 'assign_to', agentId: 'usr_your_best_agent' },
    { type: 'add_tags', tags: ['auto-assigned', 'urgent'] },
    { type: 'send_notification', 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.

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.

// Dry-run against an existing ticket
const { data: result } = await cstar.automations.test(rule.id, {
  resourceType: 'ticket',
  resourceId: 'tkt_abc123',
});

console.log('Would match:', result.wouldMatch);
console.log('Actions:', result.actionsWouldExecute);
# Or use the CLI
cstar automations test rule_abc --resource-type ticket --resource-id tkt_abc123

What's Next?