Issue with HTTP Request Node: {{$('Node Name').all()[0].json.VAR}} still results in invalid JSON

Summary:

When trying to dynamically pass a value from a previous node into a JSON body in the HTTP Request node (for triggering an Apify actor), n8n returns "JSON parameter needs to be valid JSON" even though the value exists and works when hardcoded.


:bulb: What I’m Trying to Do:

Use an HTTP Request node to trigger Apify’s Puppeteer Actor with a dynamic startUrls value taken from a previous node using the expression:

json

CopyEdit

"startUrls": [
  {
    "url": "{{$('Edit Fields1').all()[0].json.url}}",
    "method": "GET"
  }
]

The value exists:

json

CopyEdit

{
  "brand": "Justlease",
  "url": "https://justlease.nl/ford-private-lease"
}

But n8n gives this error:

json

CopyEdit

"error": "JSON parameter needs to be valid JSON"

:white_check_mark: What I’ve Already Tried:

  • :white_check_mark: Set node to explicitly define url as a field.
  • :white_check_mark: Tried both:
    {{$json.url}}
    {{$('Edit Fields1').all()[0].json.url}}
  • :white_check_mark: Confirmed body is set to JSON, not Raw.
  • :white_check_mark: Replaced test step with full workflow execution.
  • :white_check_mark: Confirmed it works only when hardcoded.
  • :x: Still throws 400 / Invalid Input when dynamic.

:package: What the Output Looks Like:

When using dynamic value:

swift

CopyEdit

{
  "error": {
    "message": "400 - \"{\"error\": {\"type\":\"invalid-input\",\"message\":\"The input JSON must be object, got \\\"string\\\" instead.\"}}\"",
    "name": "AxiosError"
  }
}

About n8n:

Can you please share the HTTP request node or the complete expression of the node.


{
“breakpointLocation”: “NONE”,
“browserLog”: false,
“closeCookieModals”: false,
“debugLog”: false,
“downloadCss”: true,
“downloadMedia”: true,
“excludes”: [
{
“glob”: “/**/*.{png,jpg,jpeg,pdf}”
}
],
“headless”: true,
“ignoreCorsAndCsp”: false,
“ignoreSslErrors”: false,
“injectJQuery”: true,
“keepUrlFragments”: false,
“maxCrawlingDepth”: 0,
“maxPagesPerCrawl”: 0,
“pageFunction”: “async function pageFunction(context) {\n const $ = context.jQuery;\n const url = context.request.url;\n\n const pageTitle = $(‘title’).first().text().trim();\n const h1 = $(‘h1’).first().text().trim();\n const firstH2 = $(‘h2’).first().text().trim();\n const metaDescription = $(‘meta[name="description"]’).attr(‘content’) || ‘’;\n const ogTitle = $(‘meta[property="og:title"]’).attr(‘content’) || ‘’;\n const ogDescription = $(‘meta[property="og:description"]’).attr(‘content’) || ‘’;\n const buttonTexts = $(‘button’).map((, el) => $(el).text().trim()).get().slice(0, 5);\n const linkTexts = $(‘a’).map((, el) => $(el).text().trim()).get().slice(0, 5);\n const navLinks = $(‘nav a’).map((_, el) => $(el).text().trim()).get().slice(0, 5);\n\n const visibleText = $(‘body’).text().replace(/\s+/g, ’ ').trim().substring(0, 3000);\n\n context.log.info(Scraped: ${url} - ${pageTitle});\n\n return {\n url,\n pageTitle,\n metaDescription,\n ogTitle,\n ogDescription,\n h1,\n firstH2,\n buttonTexts,\n linkTexts,\n navLinks,\n visibleText\n };\n}”,
“postNavigationHooks”: “[\n async (crawlingContext) => {\n // post navigation logic here\n }\n]”,
“preNavigationHooks”: “[\n async (crawlingContext, gotoOptions) => {\n // pre navigation logic here\n }\n]”,
“proxyConfiguration”: {
“useApifyProxy”: true
},
“runMode”: “DEVELOPMENT”,
“startUrls”: [
{
“url”: “{{ $(‘Edit Fields1’).all()[0].json.url }}”,
“method”: “GET”
}
],
“useChrome”: false,
“waitUntil”: [
“networkidle2”
],
“globs”: ,
“pseudoUrls”: ,
“proxyRotation”: “RECOMMENDED”,
“initialCookies”: ,
“maxRequestRetries”: 3,
“maxResultsPerCrawl”: 0,
“maxConcurrency”: 50,
“pageLoadTimeoutSecs”: 60,
“pageFunctionTimeoutSecs”: 60,
“maxScrollHeightPixels”: 5000,
“customData”: {}
}

{
  "breakpointLocation": "NONE",
  "browserLog": false,
  "closeCookieModals": false,
  "debugLog": false,
  "downloadCss": true,
  "downloadMedia": true,
  "excludes": [
    {
      "glob": "/**/*.{png,jpg,jpeg,pdf}"
    }
  ],
  "headless": true,
  "ignoreCorsAndCsp": false,
  "ignoreSslErrors": false,
  "injectJQuery": true,
  "keepUrlFragments": false,
  "maxCrawlingDepth": 0,
  "maxPagesPerCrawl": 0,
  "pageFunction": "async function pageFunction(context) {\n const $ = context.jQuery;\n const url = context.request.url;\n\n const pageTitle = $('title').first().text().trim();\n const h1 = $('h1').first().text().trim();\n const firstH2 = $('h2').first().text().trim();\n const metaDescription = $('meta[name=\"description\"]').attr('content') || '';\n const ogTitle = $('meta[property=\"og:title\"]').attr('content') || '';\n const ogDescription = $('meta[property=\"og:description\"]').attr('content') || '';\n const buttonTexts = $('button').map((, el) => $(el).text().trim()).get().slice(0, 5);\n const linkTexts = $('a').map((, el) => $(el).text().trim()).get().slice(0, 5);\n const navLinks = $('nav a').map((_, el) => $(el).text().trim()).get().slice(0, 5);\n\n const visibleText = $('body').text().replace(/\\s+/g, ' ').trim().substring(0, 3000);\n\n context.log.info(Scraped: ${url} - ${pageTitle});\n\n return {\n url,\n pageTitle,\n metaDescription,\n ogTitle,\n ogDescription,\n h1,\n firstH2,\n buttonTexts,\n linkTexts,\n navLinks,\n visibleText\n };\n}",
  "postNavigationHooks": "[\n async (crawlingContext) => {\n // post navigation logic here\n }\n]",
  "preNavigationHooks": "[\n async (crawlingContext, gotoOptions) => {\n // pre navigation logic here\n }\n]",
  "proxyConfiguration": {
    "useApifyProxy": true
  },
  "runMode": "DEVELOPMENT",
  "startUrls": [
    {
      "url": "{{ $('Edit Fields1').all()[0].json.url }}",
      "method": "GET"
    }
  ],
  "useChrome": false,
  "waitUntil": [
    "networkidle2"
  ],
  "globs": [],
  "pseudoUrls": [],
  "proxyRotation": "RECOMMENDED",
  "initialCookies": [],
  "maxRequestRetries": 3,
  "maxResultsPerCrawl": 0,
  "maxConcurrency": 50,
  "pageLoadTimeoutSecs": 60,
  "pageFunctionTimeoutSecs": 60,
  "maxScrollHeightPixels": 5000,
  "customData": {}
}

Some characters in pageFunction are not escaped correctly.
Escaped missing " and \ and works now.

it is not working still. I am not able to get what is the exact error is I have trying on escaping the input the whole day as I can.


{
“breakpointLocation”: “NONE”,
“browserLog”: false,
“closeCookieModals”: false,
“debugLog”: false,
“downloadCss”: true,
“downloadMedia”: true,
“excludes”: [
{
“glob”: “/**/*.{png,jpg,jpeg,pdf}”
}
],
“headless”: true,
“ignoreCorsAndCsp”: false,
“ignoreSslErrors”: false,
“injectJQuery”: true,
“keepUrlFragments”: false,
“maxCrawlingDepth”: 0,
“maxPagesPerCrawl”: 0,
“pageFunction”: “async function pageFunction(context) {\n const $ = context.jQuery;\n const url = context.request.url;\n\n const pageTitle = $(‘title’).first().text().trim();\n const h1 = $(‘h1’).first().text().trim();\n const firstH2 = $(‘h2’).first().text().trim();\n const metaDescription = $(‘meta[name="description"]’).attr(‘content’) || ‘’;\n const ogTitle = $(‘meta[property="og:title"]’).attr(‘content’) || ‘’;\n const ogDescription = $(‘meta[property="og:description"]’).attr(‘content’) || ‘’;\n const buttonTexts = $(‘button’).map((, el) => $(el).text().trim()).get().slice(0, 5);\n const linkTexts = $(‘a’).map((, el) => $(el).text().trim()).get().slice(0, 5);\n const navLinks = $(‘nav a’).map((_, el) => $(el).text().trim()).get().slice(0, 5);\n\n const visibleText = $(‘body’).text().replace(/\s+/g, ’ ').trim().substring(0, 3000);\n\n context.log.info(Scraped: ${url} - ${pageTitle});\n\n return {\n url,\n pageTitle,\n metaDescription,\n ogTitle,\n ogDescription,\n h1,\n firstH2,\n buttonTexts,\n linkTexts,\n navLinks,\n visibleText\n };\n}”,
“postNavigationHooks”: “[\n async (crawlingContext) => {\n // post navigation logic here\n }\n]”,
“preNavigationHooks”: “[\n async (crawlingContext, gotoOptions) => {\n // pre navigation logic here\n }\n]”,
“proxyConfiguration”: {
“useApifyProxy”: true
},
“runMode”: “DEVELOPMENT”,
“startUrls”: [
{
“url”: “{{ $(‘Edit Fields1’).all()[0].json.url }}”,
“method”: “GET”
}
],
“useChrome”: false,
“waitUntil”: [
“networkidle2”
],
“globs”: ,
“pseudoUrls”: ,
“proxyRotation”: “RECOMMENDED”,
“initialCookies”: ,
“maxRequestRetries”: 3,
“maxResultsPerCrawl”: 0,
“maxConcurrency”: 50,
“pageLoadTimeoutSecs”: 60,
“pageFunctionTimeoutSecs”: 60,
“maxScrollHeightPixels”: 5000,
“customData”: {}
}

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