Using values from webhook leads to error

Hi,

Describe the issue/error/question

I ran into a small issue that maybe you’ll help me fix. I’m running a webhook that delivers data, but I can’t seem to find the value identifier. The ones I’m talking about are “website”, “name” and “job”.

I tried using this {{ $json[“website”] }} but it doesn’t work, what am I doing wrong?

What is the error message (if any)?

ERROR: JSON parameter need to be an valid JSON

Please share the workflow

{
  "meta": {
    "instanceId": "fe4edacd0eb0ccbe54476072d33a2027c52f7e50364c7bf94fffc6782bc52bcc"
  },
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "https://cheatlayer.com/triggers/extension",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"start\":\"\",\"Gsheets\",\"sheet_url\":\"",\"sheet_id\":\"Sheet1\",\"sheet_data\":[\"[\"website\"]\",\"[\"name\"]\",\"[\"job\"]\"],\"key\":\""}\n",
        "options": {}
      },
      "id": "b5233328-ae09-4565-9d50-23418af397dc",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        780,
        300
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "420965b9-756e-4a00-95d8-39a1ec3b24a3",
        "options": {}
      },
      "id": "7cbff7b1-4be0-4da1-a49f-276ec0838af2",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        220,
        300
      ],
      "webhookId": "420965b9-756e-4a00-95d8-39a1ec3b24a3"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Information on your n8n setup

  • n8n version: 0.209.4
  • Database you’re using (default: SQLite):
  • Running n8n with the execution process [own(default)]:
  • Running n8n via [Docker]:

Welcome to the community @AmineB!

You can drag & drop the values. It will then automatically create the correct expression.

To answer your question. Both values are underneath body so the correct expression would be:

{{ $json["body"]["website"] }} 

Thank you Jan for your help, that seems to work along with this option {{ $node[“Webhook”].json[“body”][“name”] }}. However I’m still getting the same error with the details below. Anything I might still be doing wrong?

Here’s my HTTP request POST body, redacted the URL and API Key.

{"start":"","Gsheets","sheet_url":"SHEETS_URL","sheet_id":"Sheet1","sheet_data":["{{ $node["Webhook"].json["body"]["website"] }} ","{{ $node["Webhook"].json["body"]["name"] }} ","{{ $node["Webhook"].json["body"]["job"] }} "],"key":"API_KEY"}

and the ERROR code

NodeOperationError: JSON parameter need to be an valid JSON
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/HttpRequest/V3/HttpRequestV3.node.js:1001:31)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:658:51)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:585:68
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Thanks again for your support

Hi @AmineB, it seems your workflow JSON might have become corrupted when being pasted here on the forum, so I am not 100% sure how exactly your expression looks like.

If you have trouble building your JSON string you might find it easier to define individual fields rather than writing the whole JSON payload at once. Essentially like so:

image

This would still result in JSON being sent to the destination API:

image

1 Like

Thanks @MutedJam, it fixed the problem, but the workflow doesn’t work. It’s supposed to write down the website, name and job values in an excel sheet. I’m still missing something…

1 Like

Hey @AmineB,

That looks like n8n has sent the data and the service you are using has returned an OK message, Is that service you are using meant to be writing to the excel sheet for you? It may be worth checking with that service to see it shows any errors.

If you are saving to a Google Sheet though we do have a node for that which you could use instead which may be easier.

1 Like

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