HTTP Request Node JSON Error

Describe the problem/error/question

So I am sending a request to instantly.ai api it is a POST request to add leads to a campaign. The issue is that the JSON isn’t valid even though I have already validated it with 2 different JSON validators.

Here’s what I know so far, when I have it on fixed mode with hardcoded data it works fine. When I have it on expression mode with the input I get from my webhook I start getting the invalid JSON error.

What is the error message (if any)?

JSON parameter needs to be valid JSON

NodeOperationError: JSON parameter needs to be valid JSON at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/HttpRequest/V3/HttpRequestV3.node.js:207:39) at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:632:42) at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:872:62 at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:1206:20

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 4.2
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system: Windows 10

Welcome to the community @Logan_Spencer !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


The outcome depends on the actual value that expressions are substituted for. If you have null, arrays, and objects then the resulting JSON will break. The solutions is to include the while JSOn in the expression. Something like

{{
  {
      "api_key": "apikey",
      "campaign_id": "campaignid",
      "skip_if_in_workspace": false,
      "skip_if_in_campaign": true,
      "leads": [
          {
              "email": $('Webhook').item.json.body.agent_email,
              "first_name": $('Edit Fields').item.json['First Name']",
              "last_name": $('Edit Fields').item.json['Last Name'],
              "company_name": $('Webhook').item.json.body.broker_name,
              "personalization": $json.output,
              "phone": $('Webhook').item.json.body.agent_phones[0].number",
              "website": "instantly.ai"
          }
      ]
  }
}}