Auto-triage Gorgias tickets using n8n
Prerequisites
- n8n instance (cloud or self-hosted)
- Gorgias account with REST API access (Settings → API → REST API)
- Gorgias API credentials: your account email and API key
- Your Gorgias domain (e.g.,
your-store.gorgias.com)
Overview
This workflow receives new Gorgias tickets via webhook, extracts and normalizes the ticket text, runs keyword matching to determine the topic, then calls the Gorgias API to apply the correct tag. Because n8n sits outside Gorgias, you can extend this workflow to also log to a spreadsheet, notify Slack, or call other APIs as part of the same triage step.
Step 1: Create a Webhook trigger node
Add a Webhook node as the trigger:
- HTTP Method: POST
- Path:
gorgias-triage - Authentication: None (Gorgias doesn't sign webhooks by default)
Copy the webhook URL shown in the node — you'll paste it into Gorgias in the next step.
Step 2: Register the webhook in Gorgias
In Gorgias, go to Settings → Integrations → HTTP.
Click Add HTTP integration:
- Name: n8n Triage
- URL: Your n8n webhook URL
- Events: Ticket created
- Content-Type:
application/json
Save and enable.
The webhook payload contains the full ticket object including id, subject, messages (array — the customer's first message is messages[0]), status, tags, and the customer object with name and email.
Step 3: Extract and normalize the ticket text
Add a Code node to pull out the searchable text:
const ticket = $input.first().json;
const subject = (ticket.subject || '').toLowerCase();
const body = (ticket.messages?.[0]?.body_text || '').toLowerCase();
const combined = `${subject} ${body}`;
return [{
json: {
ticketId: ticket.id,
existingTags: ticket.tags || [],
text: combined,
}
}];Step 4: Classify the ticket with a Switch node
Add a Switch node to route based on keyword matches:
- Mode: Expression
- Value to match:
{{ $json.text }}
Cases:
| Case | Condition | Output label |
|---|---|---|
| 1 | Contains invoice OR payment OR refund OR overcharged | billing |
| 2 | Contains shipping OR tracking OR delivery OR package OR lost | shipping |
| 3 | Contains return OR exchange OR cancel OR rma | returns |
| 4 | Contains error OR bug OR broken OR not working OR crash | technical |
| 5 | Contains login OR password OR account OR locked | account |
| Default | (no match) | needs-triage |
n8n's Switch node exits on the first match. Order your cases from most specific to least specific so a ticket about "can't log in to track my order" hits the right branch (account/login) rather than a broader one.
Step 5: Fetch existing tags before updating
The Gorgias API replaces the entire tags array on update — it doesn't append. Add an HTTP Request node before the tag write to fetch the current ticket state:
- Method: GET
- URL:
https://your-store.gorgias.com/api/tickets/{{ $('Code').item.json.ticketId }} - Authentication: Basic Auth
- Username: your Gorgias email
- Password: your Gorgias API key
Then add another Code node to merge the new tag with the existing ones:
const currentTags = $input.first().json.tags || [];
const newTag = $('Switch').item.json.tag; // pass tag from Switch output
// Avoid duplicate tags
const merged = [...currentTags, { name: newTag }].filter(
(tag, i, arr) => arr.findIndex(t => t.name === tag.name) === i
);
return [{ json: { mergedTags: merged } }];Step 6: Apply the tag via Gorgias API
Add an HTTP Request node to update the ticket:
- Method: PUT
- URL:
https://your-store.gorgias.com/api/tickets/{{ $('Code').item.json.ticketId }} - Authentication: Basic Auth (same credentials)
- Body (JSON):
{
"tags": {{ $json.mergedTags }}
}In Gorgias: Settings → API → REST API. Create a new key and copy it — it's only shown once. Store it in n8n as a credential, not inline in node config.
Step 7: Add error handling and activate
- Enable Retry On Fail on both HTTP Request nodes (2 retries, 5 second wait)
- Add an Error Workflow to alert you via email or Slack if the workflow fails
- Run a test by creating a ticket in Gorgias that matches one of your keyword cases
- Toggle the workflow to Active
Cost
- n8n Cloud: Each ticket creates ~5 node executions. 500 tickets/month = ~2,500 executions. Within the Starter plan limit.
- Self-hosted: Free.
Need help implementing this?
We build and optimize automation systems for mid-market businesses. Let's discuss the right approach for your team.