Describe the problem/error/question
I built a workflow with n8n that was triggered when it received tickets from FreshDesk after they are created and passed the data through an AI agent node for routing to the appropriate channel. When the response from the AI agent is “SPEAK TO AGENT” the flow will trigger an email node to send an email to my company’s support email account that a request to speak with an agent has been made – The problem with this is that it created an infinite loop of tickets and emails to be created which led to me deactivating the flow. Afterwards, FreshDesk was no longer triggering n8n’s webhook.
What is the error message (if any)?
Response Code: 404 Headers: {“connection”=>[“close”], “transfer-encoding”=>[“chunked”], “cf-cache-status”=>[“DYNAMIC”], “cf-ray”=>[“98ede0898937d6b7-IAD”], “content-type”=>[“application/json; charset=utf-8”], “date”=>[“Wed, 15 Oct 2025 08:16:55 GMT”], “etag”=>[“W/\“106-FJ76UljcZtTEjYZl3weB2wkCF/4\””], “nel”=>[“{\“report_to\”:\“cf-nel\”,\“success_fraction\”:0.0,\“max_age\”:604800}”], “referrer-policy”=>[“same-origin”], “report-to”=>["{\“group\”:\“cf-nel\”,\“max_age\”:604800,\“endpoints\”:[{\“url\”:\"https://a.nel.cloudflare.com/report/v4?s=QB1t%2BvLWzkCKb%2FsMjowSxcB1MfK7zH%2B%2FRfl5NA7eq%2BVm9vDXwtqZHYoK2huTg7BY1XZxMomt902F2NUFrmb1cGGt5X%2F00KJPbhQ0FVRpXDAPD5WAz8csDBaR7w%3D%3D\\“}\]}”\], “server”=>[“cloudflare”], “strict-transport-security”=>[“max-age=15552000; includeSubDomains”], “vary”=>[“Accept-Encoding, Accept-Encoding”], “x-content-type-options”=>[“nosniff”], “x-frame-options”=>[“SAMEORIGIN”], “x-fw-edge-server”=>[“fwe”], “x-request-id”=>[“32a14ee0-e78b-484e-aaed-ce4fb6119da1”]}
PS: This error message was obtained from FreshDesk’s server logs when I got on a zoom call with the support team
Please share your workflow
{
"nodes": [
{
"parameters": {
"promptType": "define",
"text": "={{ $json.chatInput }}",
"options": {
"systemMessage": "=You are an AI assistant that classifies Freshdesk ticket descriptions into predefined request categories.\n\nInstructions:\n\nYou will receive a Freshdesk ticket description along with requester details.\n\nAnalyze the description and determine the correct category from the following list:\n\nREFUND → if the description mentions \"refund\" or a related phrase.\n\nLOAN PAYMENT → if it mentions \"loan payment\" or a related phrase.\n\nLOAN STATEMENT → if it mentions \"loan statement\" or a related phrase.\n\nLOAN BALANCE → if it mentions \"loan balance\" or a related phrase.\n\nLOAN REQUEST → if it mentions \"loan request\" or a related phrase.\n\nELIGIBILITY → if it mentions \"not eligible\" or \"eligibility\" or \"qualified\" or a related phrase.\n\nFAILED LOAN → if it mentions \"loan request failed\" or a related phrase\n\nSALARY INFORMATION UPDATE → if it mentions \"salary details\" or \"salary information update\" or a related phrase\n\nSPEAK WITH AGENT → if it mentions \"speak with agent\" or \"speak with customer care\" or a related phrase\ne.g\n\ndescription_text: \"I mistakenly sent a refund request yesterday, please confirm.\"\nrequester:{\n \"id\": 6101301230,\n \"name\": \"John Doe\",\n \"email\": \"[email protected]\",\n \"mobile\": 8123456789,\n \"phone\": 9087654321\n}\nOutput:\n{\n \"description\": \"REFUND\",\n \"ticket_id\": 6101301\n \"requester\": {\n \"id\": 6101301230,\n \"name\": \"John Doe\",\n \"email\": \"[email protected]\",\n \"mobile\": 8123456789,\n \"phone\": 9087654321\n }\n}\n\nStrictly follow these rules:\n\nRules:\n\nThe \"description\" field must contain only one category in ALL CAPS.\n\nDo not invent categories outside the list.\n\nAlways include the requester object exactly as it was passed in.\n\nIf the message sounds salesy like and ad do not continue the execution.\n\nIf more than one condition is met, return all the categories that meet the condition in a string with each condition separated by a comma.\n"
}
},
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 2.2,
"position": [
-464,
800
],
"id": "784c8dde-1e84-443c-8fa4-848268458d60",
"name": "AI Agent",
"alwaysOutputData": true,
"retryOnFail": true,
"maxTries": 2
},
{
"parameters": {
"rules": {
"values": [
{
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose",
"version": 2
},
"conditions": [
{
"leftValue": "=REFUND",
"rightValue": "={{ $json.description }}",
"operator": {
"type": "string",
"operation": "contains"
},
"id": "27e4c22a-6f43-475f-8fc9-d3ca2be655d8"
}
],
"combinator": "and"
}
},
{
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose",
"version": 2
},
"conditions": [
{
"id": "131b5f20-9dff-4961-bdbd-0efdc90d6de8",
"leftValue": "LOAN PAYMENT",
"rightValue": "={{ $json.description }}",
"operator": {
"type": "string",
"operation": "contains"
}
}
],
"combinator": "and"
}
},
{
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose",
"version": 2
},
"conditions": [
{
"id": "785c4188-e61c-4eea-ade7-63c05b6ed8ac",
"leftValue": "LOAN STATEMENT",
"rightValue": "={{ $json.description }}",
"operator": {
"type": "string",
"operation": "contains"
}
}
],
"combinator": "and"
}
},
{
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose",
"version": 2
},
"conditions": [
{
"id": "6306118b-6668-41a9-92a8-45850fe8d61e",
"leftValue": "LOAN BALANCE",
"rightValue": "={{ $json.description }}",
"operator": {
"type": "string",
"operation": "contains"
}
}
],
"combinator": "and"
}
},
{
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose",
"version": 2
},
"conditions": [
{
"id": "5e072827-489f-40d2-8dd3-61a9a141fce2",
"leftValue": "LOAN REQUEST",
"rightValue": "={{ $json.description }}",
"operator": {
"type": "string",
"operation": "contains"
}
}
],
"combinator": "and"
}
},
{
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose",
"version": 2
},
"conditions": [
{
"id": "a43e458d-44fd-4c1a-b53b-86a939015d2d",
"leftValue": "={{ $json.description }}",
"rightValue": "ELIGIBILITY",
"operator": {
"type": "string",
"operation": "contains"
}
}
],
"combinator": "and"
}
},
{
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose",
"version": 2
},
"conditions": [
{
"id": "c4b9718c-78ee-45dc-8ff0-384212c5c7db",
"leftValue": "={{ $json.description }}",
"rightValue": "ELIGIBILITY",
"operator": {
"type": "string",
"operation": "contains"
}
}
],
"combinator": "and"
}
},
{
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose",
"version": 2
},
"conditions": [
{
"id": "115611c2-27a4-40ae-b384-9516684779b8",
"leftValue": "={{ $json.description }}",
"rightValue": "SALARY INFORMATION UPDATE",
"operator": {
"type": "string",
"operation": "contains"
}
}
],
"combinator": "and"
}
},
{
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose",
"version": 2
},
"conditions": [
{
"id": "dcb43802-0674-4a81-a276-2ae4238be435",
"leftValue": "={{ $json.description }}",
"rightValue": "SPEAK WITH AGENT",
"operator": {
"type": "string",
"operation": "contains"
}
}
],
"combinator": "and"
}
},
{
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose",
"version": 2
},
"conditions": [
{
"id": "d6f4face-5f61-40ba-a26e-9a6658ce1c54",
"leftValue": "={{ $json.description }}",
"rightValue": "FAILED LOAN",
"operator": {
"type": "string",
"operation": "contains"
}
}
],
"combinator": "and"
}
}
]
},
"looseTypeValidation": true,
"options": {
"allMatchingOutputs": true
}
},
"type": "n8n-nodes-base.switch",
"typeVersion": 3.2,
"position": [
256,
672
],
"id": "726e6b01-667e-4e74-9ae3-71cd1414222d",
"name": "Switch"
},
{
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini"
},
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1.2,
"position": [
-560,
1024
],
"id": "20bb708c-3e73-4da0-b2a3-8749b733bb61",
"name": "OpenAI Chat Model",
"credentials": {
"openAiApi": {
"id": "adMHNk2pd6Uwi7CA",
"name": "OpenAi account 2"
}
}
},
{
"parameters": {
"sessionIdType": "customKey",
"sessionKey": "={{ $('Code1').item.json.chatInput.json.ticket_id }}"
},
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"typeVersion": 1.3,
"position": [
-432,
1056
],
"id": "69229370-6c60-4b0b-b594-538c3c2ca9c6",
"name": "Simple Memory"
},
{
"parameters": {
"url": "=https://libertyassured.freshdesk.com/api/v2/tickets/ {{ $json.body.id }}",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "include",
"value": "requester"
}
]
},
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Basic d24xa3RrSVlyNnVQV1lzM04wWU8=:X\"\n}",
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
-912,
800
],
"id": "15c4f8dc-2187-4930-9daf-14263ae89910",
"name": "Retrieve Message from Tickets",
"credentials": {
"httpHeaderAuth": {
"id": "6yodtfNnO1oKY1Ll",
"name": "Freshdesk Header Auth"
}
}
},
{
"parameters": {
"language": "python",
"pythonCode": "import json\n\noutput = []\nfor item in _input.all():\n raw = item.json.get(\"output\", \"{}\")\n parsed = json.loads(raw)\n\n # Always include these fields\n requester = parsed.get(\"requester\", {}) or {}\n flattened = {\n \"description\": parsed.get(\"description\", {}),\n \"ticket_id\": parsed.get(\"ticket_id\", {}),\n \"id\": requester.get(\"id\", {}),\n \"name\": requester.get(\"name\", {}),\n \"email\": requester.get(\"email\", {}),\n \"mobile\": requester.get(\"mobile\", {}),\n \"phone\": requester.get(\"phone\", {}),\n }\n\n output.append({\"json\": flattened})\n\nreturn output\n"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-96,
800
],
"id": "4bdd1341-f8fc-4d97-ba32-91e190d76fc6",
"name": "Code"
},
{
"parameters": {
"language": "python",
"pythonCode": "import re\n\noutput = []\nfor item in _input.all():\n # raw_text = item.json.get(\"description_text\", \"\")\n raw_text = item.json.get(\"subject\", \"\")\n # Remove all whitespace (\\r, \\n, tabs) and collapse to single space\n cleaned = re.sub(r\"\\s+\", \" \", raw_text).strip()\n \n # Build a single JSON object with both fields\n inputs = {\n \"json\": {\n \"description\": cleaned,\n \"requester\": item.json.get(\"requester\", \"\"),\n \"ticket_id\": item.json.get(\"id\", \"\")\n }\n }\n output.append({\"chatInput\": inputs})\n\nreturn output\n"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-688,
800
],
"id": "6a54dac0-b663-4bfa-a07c-5fb753a32a3e",
"name": "Code1"
},
{
"parameters": {
"fromEmail": "[email protected]",
"toEmail": "[email protected]",
"subject": "n8n Test Email",
"html": "=<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Failed Loan Complaint</title>\n</head>\n<body style=\"font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;\">\n <div style=\"background-color: #f4f4f4; padding: 20px; border-radius: 8px;\">\n <h2 style=\"color: #007bff; text-align: center;\">Support Request</h2>\n <p>Dear Agent please a customer with this ticket: {{ $json.ticket_id }} has requested to speak with an agent. Please do well to follow up cheers!</p>\n <hr style=\"border: none; border-top: 1px solid #ddd; margin: 20px 0;\">\n <p style=\"font-size: 12px; color: #666; text-align: center;\">\n This email was sent from n8n. Reply to discuss further.\n </p>\n </div>\n</body>\n</html> ",
"options": {}
},
"type": "n8n-nodes-base.emailSend",
"typeVersion": 2.1,
"position": [
-16,
1296
],
"id": "1fa7f5e8-b917-44d4-b2c5-ded87efed4e8",
"name": "Send email14",
"webhookId": "1e7a6a44-8474-4c85-82f0-a94f7044f2d7",
"credentials": {
"smtp": {
"id": "xZ9XBBihf3YTykva",
"name": "SMTP account"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "8901fc23-f49f-43e7-b641-d49b416a61c3",
"options": {}
},
"type": "n8n-nodes-base.webhook",
"typeVersion": 2.1,
"position": [
-1152,
800
],
"id": "491c304f-70cf-4bfd-a89c-3b6a2eb9bc32",
"name": "Webhook1",
"webhookId": "8901fc23-f49f-43e7-b641-d49b416a61c3"
}
],
"connections": {
"AI Agent": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Switch": {
"main": [
[],
[],
[],
[],
[],
[],
[],
[],
[
{
"node": "Send email14",
"type": "main",
"index": 0
}
],
[]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Simple Memory": {
"ai_memory": [
[
{
"node": "AI Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"Retrieve Message from Tickets": {
"main": [
[
{
"node": "Code1",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "Switch",
"type": "main",
"index": 0
}
]
]
},
"Code1": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Send email14": {
"main": [
[]
]
},
"Webhook1": {
"main": [
[]
]
}
},
"pinData": {
"Retrieve Message from Tickets": [
{
"cc_emails": [],
"fwd_emails": [],
"reply_cc_emails": [],
"ticket_cc_emails": [],
"ticket_bcc_emails": [],
"fr_escalated": true,
"spam": false,
"email_config_id": 61000025971,
"group_id": 61000045320,
"priority": 4,
"requester_id": 61038212804,
"responder_id": null,
"source": 3,
"company_id": 61000313004,
"status": 2,
"subject": "I want to speak with an agent",
"association_type": null,
"support_email": null,
"to_emails": null,
"product_id": 61000000646,
"id": 143201,
"type": "Refund",
"due_by": "2025-10-15T13:19:05Z",
"fr_due_by": "2025-10-15T10:19:05Z",
"is_escalated": false,
"custom_fields": {
"cf_liberty_products": "Payday",
"cf_reasonenquiry": null
},
"created_at": "2025-10-15T09:19:04Z",
"updated_at": "2025-10-15T10:23:18Z",
"associated_tickets_count": null,
"tags": [],
"requester": {
"id": 61038212804,
"name": "Ini-ubong Isemin",
"email": "[email protected]",
"mobile": "08034860888",
"phone": "08034860888"
},
"structured_description": null,
"internal_agent_id": null,
"internal_group_id": null,
"nr_due_by": null,
"nr_escalated": false
}
],
"Code1": [
{
"chatInput": {
"json": {
"description": "I want to speak with an agent",
"requester": {
"id": 61038212804,
"name": "Ini-ubong Isemin",
"email": "[email protected]",
"mobile": "08034860888",
"phone": "08034860888"
},
"ticket_id": 143201
}
}
}
],
"Send email14": [
{
"accepted": [
"[email protected]"
],
"rejected": [],
"ehlo": [
"SIZE 52428800",
"LIMITS MAILMAX=1000 RCPTMAX=50000",
"8BITMIME",
"PIPELINING",
"PIPECONNECT",
"AUTH PLAIN LOGIN",
"HELP"
],
"envelopeTime": 480,
"messageTime": 320,
"messageSize": 1565,
"response": "250 OK id=1v4eAM-00000002fBe-0h3j",
"envelope": {
"from": "[email protected]",
"to": [
"[email protected]"
]
},
"messageId": "<[email protected]>"
}
]
},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "2b8cd597d597b40ec4b87530fa7008d87f90475d582bb90cd0685371bf02aa14"
}
}
Share the output returned by the last node
[
{
"accepted": [
"[email protected]"
],
"rejected": [],
"ehlo": [
"SIZE 52428800",
"LIMITS MAILMAX=1000 RCPTMAX=50000",
"8BITMIME",
"PIPELINING",
"PIPECONNECT",
"AUTH PLAIN LOGIN",
"HELP"
],
"envelopeTime": 480,
"messageTime": 320,
"messageSize": 1565,
"response": "250 OK id=1v4eAM-00000002fBe-0h3j",
"envelope": {
"from": "[email protected]",
"to": [
"[email protected]"
]
},
"messageId": "<[email protected]>"
}
]
Information on your n8n setup
- n8n version: 1.115.3
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
- Operating system: