HTTP Request: "ERROR: JSON parameter need to be an valid JSON"

I keep having the “ERROR: JSON parameter need to be an valid JSON” message for my http request node, but I ran the same json on Postman and it worked normally, don’t know what to do…

Hey @kilter,

Looking at the expression you are using the JSON doesn’t appear to be value. Can you share the expression you are using and the input data for the node if you are using any of that in the JSON.

It could just be a case of adding an extra { } in your expression so something like {{ { "x":"y" } }}

Sure, this is the expression I’m using int the boddy:

{{
    "number": "5541997692169",
    "text": "Top, APIGRATIS! Que massa.",
    "time_typing": "1"
}}

Even when I add extra {} like you said, the error massage remains the same:

{{
    {"number": "5541997692169"},
    {"text": "Top, APIGRATIS! Que massa."},
    {"time_typing": "1"}
}}

I ran this code on Postman and it went perfectly, but I keep having the JSON error on n8n:

{
    "number": "5531994359434",
    "text": "Top, APIGRATIS! Que massa.",
    "time_typing": 1
}

These expressions are neither equivalent nor valid.


You need:

{{
{
    "number": "5531994359434",
    "text": "Top, APIGRATIS! Que massa.",
    "time_typing": 1
}
}}

which is what you are using in Postman.

1 Like

Tried it as well, but the error remains:

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:1076:35)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:646:51)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:631:68
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Hey @kilter,

Are you trying to use expressions as well? For me the example workflow below is working, It is also showing that the JSON field is an object which is important if you are using the expression option.

image

That’s wierd, I’m using the excat same code and getting the error
Tried to change the header as well, but the result is the same…
Could it be anything else? This is my workflow:

Hey @kilter,

Can you share the acutal json for the worklfow? That will allow us to click around the workflow and see what is in there.

Sure, here you go:

Hey @kilter,

I have had a very quick play and the issue is actually with the header json and you might have found a bug, Can you try using the below for the header and let me know if it works after replacing the REMOVED text.

{{
JSON.stringify({
    'Content-Type': 'application/json', 
    'SecretKey': 'REMOVED', 
    'PublicToken': 'REMOVED', 
    'DeviceToken': 'REMOVED', 
    'Authorization': 'Bearer REMOVED'
})  
}}

It didn’t work perfectly, but something changed with this code, the error is different now:
“ERROR: Authorization failed - please check your credentials”

But I don’t really think it is a problem with my API credentials, since the same ones worked out fine on Postman. Here’s the code for the error:

{"status":"rejected","reason":{"message":"401 - \"{\\\"error\\\":true,\\\"message\\\":{\\\"message\\\":\\\"Telefone n\\\\u00e3o informado.\\\"},\\\"device\\\":{\\\"status\\\":\\\"CONNECTED\\\",\\\"device_token\\\":\\\"fae21a34-b22d-41ac-a543-1d9e8e446e74\\\",\\\"device_name\\\":\\\"virtual 5100\\\"},\\\"response\\\":null}\"","name":"Error","stack":"Error: 401 - \"{\\\"error\\\":true,\\\"message\\\":{\\\"message\\\":\\\"Telefone n\\\\u00e3o informado.\\\"},\\\"device\\\":{\\\"status\\\":\\\"CONNECTED\\\",\\\"device_token\\\":\\\"fae21a34-b22d-41ac-a543-1d9e8e446e74\\\",\\\"device_name\\\":\\\"virtual 5100\\\"},\\\"response\\\":null}\"\n    at createError (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/settle.js:17:12)\n    at RedirectableRequest.handleResponse (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/adapters/http.js:238:9)\n    at RedirectableRequest.emit (node:events:525:35)\n    at RedirectableRequest.emit (node:domain:489:12)\n    at RedirectableRequest._processResponse (/usr/local/lib/node_modules/n8n/node_modules/follow-redirects/index.js:356:10)\n    at ClientRequest.RedirectableRequest._onNativeResponse (/usr/local/lib/node_modules/n8n/node_modules/follow-redirects/index.js:62:10)\n    at Object.onceWrapper (node:events:628:26)\n    at ClientRequest.emit (node:events:525:35)\n    at ClientRequest.emit (node:domain:489:12)\n    at HTTPParser.parserOnIncomingClient (node:_http_client:701:27)\n    at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)\n    at TLSSocket.socketOnData (node:_http_client:542:22)\n    at TLSSocket.emit (node:events:513:28)\n    at TLSSocket.emit (node:domain:489:12)\n    at addChunk (node:internal/streams/readable:324:12)\n    at readableAddChunk (node:internal/streams/readable:297:9)\n    at TLSSocket.Readable.push (node:internal/streams/readable:234:10)\n    at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)\n    at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17)"}}

Hey @kilter,

It looks like the response back is from the api, Do you have a link to the api docs? typically a 401 is fairly standard but they have included some body data as well so I suspect it could be the auth has failed but I don’t know why.

I couldn’t find the problem with the auth as well, since I used the same codes and keys on Postman and it worked.

The API doc’s for this service is closed for the account, but here is a print and the github link if it helps:

Link: APIBrasil · GitHub

It could be worth getting in touch with them to see if they can tell you what the json in the error response is.

1 Like

Hey @Jon

I’m waiting for the API service’s analytics, but is there any chance n8n has a bug with the Bearer Token authorization on the header?

Since the auth worked on Postman but not on n8n, I thougth it may be a possibility…

Hey @kilter,

It is always possible, As a test you could send the data to something like webhook.site to see what the output is.

Yeah, it works via webhook…
How can I solve it using the bearer token on the http request then?

Hey @kilter,

Did you try sending the request from n8n to webhook.site or similar to see what the header is? If you have and it looks to be correct then it won’t be an issue with the bearer token process which a lot of our nodes use in the same way.

Yeah, this is the header when the n8n webhook recives signal from the API:


"headers":
{
"host":
"n8n.deltandallagnol.com.br",
"user-agent":
"APIBRASIL/1.0",
"content-length":
"2368",
"content-type":
"application/json",
"device":
"fae21a34-b22d-41ac-a543-1d9e8e446e74",
"origin":
"https://apibrasil.com.br",
"service":
"api-whatsapp",
"version":
"2.2330.11",
"x-forwarded-for":
"187.73.180.68",
"x-forwarded-host":
"n8n.deltandallagnol.com.br",
"x-forwarded-proto":
"https",
"accept-encoding":
"gzip"
},