API Call JSON Data

Hi everyone,
Before anything else: I am not a coder. I am just a small business owner that’s using n8n for the first time and setting stuff up with youtube and chatgpt’s help. So, if I say something inappropriate or stupid, please correct me and I will try my best not to do it again.

Here’s my problem:

I have a contact form on my website, that sends the webhook the following data:

[
  {
    "headers": {
      "host": "n8n.xyz.net",
      "user-agent": "WordPress/6.6.2; https://abc.com",
      "content-length": "581",
      "accept": "*/*",
      "accept-encoding": "gzip, br",
      "cdn-loop": "cloudflare; loops=1",
      "cf-connecting-ip": "2a02:4780:11:1226:0:e95:9dd7:xxxx",
      "cf-ipcountry": "IN",
      "cf-ray": "8dad3ebd4cc13bb0-BOM",
      "cf-visitor": "{\"scheme\":\"https\"}",
      "cf-warp-tag-id": "c473a44d-5f33-48d5-809f-a44afc14eaa2",
      "connection": "keep-alive",
      "content-type": "application/x-www-form-urlencoded",
      "x-forwarded-for": "2a02:4780:11:1226:0:e95:9dd7:xxxx",
      "x-forwarded-proto": "https"
    },
    "params": {},
    "query": {},
    "body": {
      "entries": "{\"iei-contact-form-first-name\":\"testing3\",\"iei-contact-form-last-name\":\"contact\",\"iei-contact-form-email-address\":\"[email protected]\",\"iei-contact-form-phone\":\"+919191919191\",\"iei-contact-form-customer-type\":\"founder\",\"iei-contact-form-location\":\"\",\"iei-contact-form-subject-line\":\"fdsfgsdf\",\"iei-contact-form-message\":\"fdsfs\"}",
      "entry_id": "6730",
      "form_id": "766",
      "version": "3.9.0",
      "file_uploads": "null",
      "referrer_url": "https://abc.com/contact-us/?v=6470f4a3ad01"
    },
    "webhookUrl": "https://n8n.xyz.net/webhook-test/efe9acba-0893-41fd-af24-34a73eb97067",
    "executionMode": "test"
  }
]

which I passed to “Set” module (because I saw a post here saying that’s what should be used) and I get the output:

[
  {
    "iei-contact-form-first-name": "testing2",
    "iei-contact-form-last-name": "contact",
    "iei-contact-form-email-address": "[email protected]",
    "iei-contact-form-phone": "+919191919191",
    "iei-contact-form-customer-type": "founder",
    "iei-contact-form-location": "",
    "iei-contact-form-subject-line": "fdsfgsdf",
    "iei-contact-form-message": "hfdgdg"
  }
]

which I pass to an HTTP Request to call my CRM’s API. If I hard-code the values, it works, so I know there’s no errors in calling it.

this is the body text I pass to the API call:

{
    "query": "mutation createOrUpdateContact($input: CreateContactInput!) { createContact(input: $input) { id } }",
    "variables": {
        "input": {
            "email": {{ $json["iei-contact-form-email-address"] }} ,
            "firstName": {{ $json["iei-contact-form-first-name"] }},
            "lastName": {{ $json["iei-contact-form-last-name"] }},
            "audienceId": "10717405865239368",
            "profile": [
                {
                    "dataFieldId": "10373567253869411",
                    "value": {{ $json["iei-contact-form-phone"] }}
                }
            ],
            "groupIds": [],
            "updateExisting": true
        }
    }
}
  

but I get this error:

{
  "errorMessage": "JSON parameter needs to be valid JSON",
  "errorDetails": {},
  "n8nDetails": {
    "nodeName": "HTTP Request",
    "nodeType": "n8n-nodes-base.httpRequest",
    "nodeVersion": 4.2,
    "itemIndex": 0,
    "time": "10/30/2024, 11:58:49 PM",
    "n8nVersion": "1.64.3 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "NodeOperationError: JSON parameter needs to be valid JSON",
      "    at Object.execute (/home/pi/.nodejs_global/lib/node_modules/n8n/node_modules/n8n-nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts:341:14)",
      "    at Workflow.runNode (/home/pi/.nodejs_global/lib/node_modules/n8n/node_modules/n8n-workflow/src/Workflow.ts:1382:31)",
      "    at /home/pi/.nodejs_global/lib/node_modules/n8n/node_modules/n8n-core/src/WorkflowExecute.ts:1167:42",
      "    at /home/pi/.nodejs_global/lib/node_modules/n8n/node_modules/n8n-core/src/WorkflowExecute.ts:1887:11"
    ]
  }
}

I used the expression thingie and dragged/dropped the values from the input.

I checked the docs and it said something about JMESPath, and when I used that, all the outputs come out as “undefined”.

Please help.

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Hi @fpcteam ,

Welcome to the community! :heart:
Don’t you worry - no stupid questions here.

I think you might be dragging the inputs directly into the JSON instead of using them as expressions. Which means you end up with n8n syntax mixed in with regural JSON syntax.
But I would be able to confirm this better if I saw how you’re setting the parameters in your HTTP Request.

Would you be able to share your workflow?

Here's how you can do it -

Export and import workflows | n8n Docs)
And then click the </> option above in this text area and paste your code between the quotation marks using ctr+v

In case it helps, you can also use a tool like this - https://jsonlint.com/ - to help you see where the errors might be in a JSON file

1 Like

n8n version: 1.64.3
database: default:
execution process: i don’t know what that is. I installed it on my raspberry pi.
running via: npm
OS: debian

Hey there. thank you for being patient and understanding. :slight_smile:

here’s the json code you requested:

I have edited my api key and account id for security sake. the api call works when I hard-code all the field values, so nothing wrong there.

Hope that helps. Looking forward to your reply.

Hi there again. your clue about dragging and dropping cleared a bit for me. I was removing the “” and then dragging the input fields. this time I dragged it between the “” and it worked.

thank you so much. big hugs to you.

1 Like

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