Hello everyone,
I am currently working on an n8n workflow where I am using the HTTP Request node to send requests. The request body is a JSON object which includes a ‘queries’ property.
The value of ‘queries’ is a string that includes search phrases surrounded by double quotes (") as part of the search criteria. For example:
swiftCopy code
"queries": "site:stackoverflow.com/users/ \"Artificial Intelligence\" OR \"AI\" OR \"Machine Learning\" OR \"ML\" OR \"Deep Learning\" OR \"Neural Networks\" OR \"Tensorflow\" OR \"Pytorch\" \"Munich\"",
I’ve noticed that when my ‘queries’ string includes these double quotes, I get an error in the n8n HTTP Request node that says “JSON parameter need to be a valid JSON”. But when I use a simpler string without double quotes, the request goes through fine.
I’ve tried various ways to escape the quotes, including using backslashes (") and replacing the double quotes with single quotes ('), but I still get the same error. I’ve also tried using different methods to construct the ‘queries’ string dynamically in a Function node before the HTTP Request node, but this hasn’t solved the issue either.
Has anyone faced a similar issue, or does anyone have suggestions on how to handle this? Any help would be greatly appreciated.
Thank you!
Please share your workflow
## Share the output returned by the last node
{
"meta": {
"instanceId": "240223e06656e67cee425800d602013033815f933bef971218cf5a1dde8ef93f"
},
"nodes": [
{
"parameters": {
"jsCode": "\nfor (const item of $input.all()) {\n item.json.myNewField = 1;\n item.json['query'] = item.json['query'].replace(/\"/g, \"'\");\n item.json['nb_profiles'] = parseInt(item.json['nb_profiles']);\n item.json['country'] = item.json['country'].toLowerCase();\n item.json['language'] = item.json['language'].toLowerCase();\n\n}\n\nreturn $input.all();\n"
},
"id": "5cb0b4d8-cf33-4941-9169-577f8d9c8ce8",
"name": "Code",
"type": "n8n-nodes-base.code",
"typeVersion": 1,
"position": [
940,
440
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.url }}",
"operation": "contains",
"value2": "stackoverflow.com"
}
]
}
},
"id": "84618a3e-ce6b-47f2-9d04-c8136ef1382b",
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
1360,
440
]
},
{
"parameters": {
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
},
"documentId": {
"__rl": true,
"value": "1G5MBU9kyvShOUVbdmFjZZKZtwAxN-x43Gh_hqwGu9vo",
"mode": "list",
"cachedResultName": "Candidates_data",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1G5MBU9kyvShOUVbdmFjZZKZtwAxN-x43Gh_hqwGu9vo/edit?usp=drivesdk"
},
"sheetName": {
"__rl": true,
"value": "gid=0",
"mode": "list",
"cachedResultName": "entry",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1G5MBU9kyvShOUVbdmFjZZKZtwAxN-x43Gh_hqwGu9vo/edit#gid=0"
},
"options": {}
},
"id": "4c34b2eb-1ab4-4f21-9a70-0e349226a127",
"name": "Candidates Data",
"type": "n8n-nodes-base.googleSheetsTrigger",
"typeVersion": 1,
"position": [
720,
440
],
"credentials": {
"googleSheetsTriggerOAuth2Api": {
"id": "20",
"name": "Google 3"
}
}
},
{
"parameters": {
"method": "POST",
"url": "https://api.apify.com/v2/acts/apify~google-search-scraper/run-sync-get-dataset-items?",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "Bearer REDACTED"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={ \n\"queries\": \"{{ $json[\"query\"] }}\",\n\"countryCode\": \"{{ $json[\"country\"] }}\", \n\"includeUnfilteredResults\": false, \n\"languageCode\": \"{{ $json[\"language\"] }}\", \n\"maxPagesPerQuery\": 1, \n\"mobileResults\": false, \n\"resultsPerPage\": {{ $json[\"nb_profiles\"] }}, \n\"saveHtml\": false, \n\"saveHtmlToKeyValueStore\": false, \n\"maxConcurrency\": 10 \t \n}",
"options": {}
},
"id": "6cdaa930-e5da-4afa-9ba4-8f66db5a2b0b",
"name": "Google Search Results",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [
1160,
440
]
}
],
"connections": {
"Code": {
"main": [
[
{
"node": "Google Search Results",
"type": "main",
"index": 0
}
]
]
},
"Candidates Data": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Google Search Results": {
"main": [
[
{
"node": "IF",
"type": "main",
"index": 0
}
]
]
}
}
}