Invalid json, bad params, bad request... please kill me

Problem: trying to set up a workflow that will automatically respond to leads via instantly. Getting stuck on teh last node where instantly sends all the info to the api for it to actually send the message. I’m sure there are other errors but i have been stuck here all day and about to go postal.

Have gotten multiple errors, but I believe the gist of it is that the json is not being recognized. I’m trying to pass various fields through teh workflow but i keep getting errors that they’re invalid.

workflow:

{
“name”: “My workflow 7”,
“nodes”: [
{
“parameters”: {
“httpMethod”: “POST”,
“path”: “instantly-webhook”,
“options”: {}
},
“id”: “13a6f314-d77e-4b9f-861f-8180bf0b5f15”,
“name”: “Webhook1”,
“type”: “n8n-nodes-base.webhook”,
“typeVersion”: 1,
“position”: [
-1440,
580
],
“webhookId”: “webhook-instantly”
},
{
“parameters”: {
“resource”: “assistant”,
“assistantId”: {
“__rl”: true,
“value”: “YOUR_ASSISTANT_ID”,
“mode”: “list”,
“cachedResultName”: “Jon”
},
“prompt”: “define”,
“text”: “=You are a helpful, friendly SDR for Tool Delta.\n\nTool Delta helps businesses grow by automating:\n- Appointment booking\n- Chatbots\n- Lead reactivation via SMS\n\n—\n\nLEAD INFO:\nFirst Name: {{$json.first_name}}\nTitle: {{$json.title}}\nCompany: {{$json.organization_name}}\nDescription: {{$json.organization_short_description}}\nCity: {{$json.city}}, {{$json.state}}\n\n—\n\nLEAD’S REPLY (latest message on top):\n\n{{$json.lead_reply_text}}\n\n—\n\nYour task:\n\n1. Based on the tone and wording, decide if the lead is interested in booking a call.\n - If the message clearly shows interest or excitement (e.g. "yes", "sounds good", "let’s do it", "send the link", etc.), mark \"interested\": \"YES\"\n - If the message says "no", "not now", "not interested", or sounds like a rejection, mark \"interested\": \"NO\"\n - If the message includes a question but sounds open-minded, treat as \"YES\"\n\n2. Then, write a natural, friendly reply in your own words, as if you’re a human SDR named {{$json.sendingaccountfirstname}}.\n\n - If interested, thank them and drop this link casually: https://calendly.com/stuart-oden\n - If not interested, thank them politely, wish them well, and stop.\n\n3. Format your replies with one sentence per paragraph, two line breaks in between paragraphs. This is for readability.\n\n4. Use only plain text. \n\nReply ONLY with valid JSON in this format \u2014 no backticks, no explanation:\n\n{\n "interested": "YES",\n "message": "your natural reply here"\n}\n”,
“options”: {}
},
“id”: “d40da0a5-8a9b-4bba-9209-8414dc1ceca0”,
“name”: “Message an assistant1”,
“type”: “@n8n/n8n-nodes-langchain.openAi”,
“typeVersion”: 1.8,
“position”: [
-1040,
580
],
“credentials”: {}
},
{
“parameters”: {
“conditions”: {
“string”: [
{
“value1”: “={{$json["interested"]}}”,
“value2”: “YES”
}
]
}
},
“id”: “acdba366-ba56-4360-b99b-72f6b86f9d65”,
“name”: “Is Interested?1”,
“type”: “n8n-nodes-base.if”,
“typeVersion”: 1,
“position”: [
-440,
580
]
},
{
“parameters”: {
“method”: “POST”,
“url”: “https://api.instantly.ai/api/v2/emails/reply”,
“authentication”: “genericCredentialType”,
“genericAuthType”: “httpHeaderAuth”,
“sendHeaders”: true,
“headerParameters”: {
“parameters”: [
{
“name”: “Authorization”,
“value”: “REPLACE_WITH_YOUR_TOKEN”
},
{
“name”: “Content-Type”,
“value”: “application/json”
}
]
},
“sendBody”: true,
“bodyParameters”: {
“parameters”: [
{
“name”: “campaign_id”,
“value”: “=$json.campaign_id”
},
{
“name”: “reply_to_uuid”,
“value”: “=$json.email_id”
},
{
“name”: “subject”,
“value”: “=$json.reply_subject”
},
{
“name”: “body”,
“value”: “=$json.message”
},
{
“name”: “eaccount”,
“value”: “=$json.email_account”
}
]
},
“options”: {}
},
“id”: “0f928b22-1bc9-4ffa-afbf-b95eff088542”,
“name”: “Send via Instantly1”,
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4,
“position”: [
-160,
560
],
“credentials”: {}
},
{
“parameters”: {
“jsCode”: “// Parse the stringified JSON from the AI assistant’s ‘output’ field\nconst aiOutput = $json.output ? JSON.parse($json.output) : {};\n\nreturn [{\n json: {\n …$json,\n interested: aiOutput.interested,\n // Escape newlines to make JSON safe\n message: (aiOutput.message || ‘’).replace(/\n/g, ‘\\n’)\n }\n}];\n”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
-660,
580
],
“id”: “68db6a58-ab75-4028-90dd-1d035aced7c6”,
“name”: “Code”
},
{
“parameters”: {
“jsCode”: “const data = $json.body || {};\n\nconst fullReply = (data.reply_text || $json.reply_text || ‘’).trim();\n\nlet text = fullReply.replace(/— MOST RECENT MESSAGE —/g, ‘’).trim();\nlet parts = text.split(‘— FULL THREAD —’);\nlet latestPart = parts.length > 0 ? parts[0].trim() : text;\nlet lines = latestPart.split(‘\n’);\nlet replyLines = ;\nfor (let line of lines) {\n let stripped = line.trim();\n if (stripped.startsWith(‘>’) || /^On .* wrote:/.test(stripped)) break;\n if (stripped === ‘’) continue;\n replyLines.push(stripped);\n}\nlet latestReply = replyLines.join(’ ‘).trim();\nif (!latestReply) latestReply = fullReply.slice(0, 300).trim();\n\nconst email = data.email_account || $json.email_account || ‘’;\nconst localPart = email.split(’@‘)[0];\nconst sendingaccountfirstname = localPart.charAt(0).toUpperCase() + localPart.slice(1);\n\nreturn [{\n json: {\n …$json,\n lead_email: data.lead_email || data.email || $json.lead_email || $json.email || ‘’,\n lead_reply_text: --- MOST RECENT MESSAGE ---\\n${latestReply}\\n\\n--- FULL THREAD ---\\n${fullReply},\n clean_lead_reply_text: latestReply,\n first_name: (data.name || $json.name || ‘’).split(’ ')[0],\n title: data.jobTitle || $json.jobTitle || ‘’,\n industry: ‘’,\n organization_name: data.organization_name || $json.organization_name || ‘’,\n organization_short_description: data.organization_short_description || $json.organization_short_description || ‘’,\n city: data.city || $json.city || ‘’,\n state: data.state || $json.state || ‘’,\n sendingaccountfirstname,\n eaccount: email\n }\n}];\n”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
-1240,
580
],
“id”: “af4e198a-b1e1-4b6b-82b3-b9e2e07591dc”,
“name”: “Code1”
},
{
“parameters”: {},
“type”: “n8n-nodes-base.merge”,
“typeVersion”: 3.2,
“position”: [
-800,
360
],
“id”: “d5cb0f3b-589f-4f44-b6c0-947f96925fe6”,
“name”: “Merge”
}
],
“pinData”: {},
“connections”: {
“Webhook1”: {
“main”: [
[
{
“node”: “Code1”,
“type”: “main”,
“index”: 0
},
{
“node”: “Merge”,
“type”: “main”,
“index”: 0
}
]
]
},
“Message an assistant1”: {
“main”: [
[
{
“node”: “Merge”,
“type”: “main”,
“index”: 1
}
]
]
},
“Is Interested?1”: {
“main”: [
[
{
“node”: “Send via Instantly1”,
“type”: “main”,
“index”: 0
}
],
[
{
“node”: “Send via Instantly1”,
“type”: “main”,
“index”: 0
}
]
]
},
“Code”: {
“main”: [
[
{
“node”: “Is Interested?1”,
“type”: “main”,
“index”: 0
}
]
]
},
“Code1”: {
“main”: [
[
{
“node”: “Message an assistant1”,
“type”: “main”,
“index”: 0
}
]
]
},
“Merge”: {
“main”: [
[
{
“node”: “Code”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“active”: true,
“settings”: {
“executionOrder”: “v1”
},
“versionId”: “b9e6e17f-5611-490a-98c7-764f90a83f83”,
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “5d59cf67cb16d3c74e811745baeeb988305ae4816cd3bbb9e7c6fc9ae01c357f”
},
“id”: “sOHWtY5oj8ZEfm3G”,
“tags”:
}

N8n setup: cloud version

any chance you can upload the workflow so it shows up in the online editor? I’m trying to open it in my instance, but the whole thing is invalid for me. The " and ’ characters are unicode, I’m not sure if that’s the website that’s doing that or what, but even when I convert them, the json is still invalid.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.