For the past day I have been struggling with the following issue:
I need to send an array via POST request.
I’ve turned on the button “json/RAW” parameters
This is the content of the body:
{"name":"name of thing","creator":"creator name","description":"this is the description "and a quote within the description"","image":"https://url_of_ image","type":"image/png","format":"none","properties":[{"key1":"value1","key2":"value2"}]}
in the header I’ve put the api key {"api-key":"abcdefghijlm"}
If I run this, I get the following error: ERROR: The data in “Body Parameters” is no valid JSON. Set Body Content Type to “RAW/Custom” for XML or other types of payloads
Right, so I tried changing the body content type to Raw/custom
Then I get the following error: ERROR: Cannot create property ‘accept’ on string ‘{“api-key”: “abcdefghijlm”}’
I’ve seen this error around on this forum, and it didn’t make it clearer for me unfortunately. (something in the lines of that it needs to be an expression - a bug of n8n. )
Hi @bees8, from looking at your example payload, it seems you are trying to send invalid JSON. Specifically, the quotes in your description field aren’t escaped and your array [{"key1":"value1","key2":"value2"}] doesn’t have a key.
If you use syntactically correct JSON the request should work as expected like so:
hey mutedjam! Thanks for the answer. The issue is that the description content is dynamic, I will not know if there are characters being used that would need an escape. How would I be able to account for that?
Regarding the array - yes I edited my json later I just typed it wrongly here!
I have used the escape characters, without avail. Actually, I used the exact same json as you, but it gave me now the second error: ERROR: Cannot create property ‘accept’ on string… etc
At least we resolved the first error
As long as your incoming data is valid JSON you wouldn’t need to worry about escaping it. Assuming your JSON comes through in a field called myBody you could do something like this:
thanks,
I cant really share the workflow, it is basically this json with a http request and an api key.
Is there a way to use an array without using the “json/raw” parameters button turned on? Because that’s when it did work (without the array). Thanks!
@MutedJam I managed to find a workaround, or even just a good solution lol.
the api key could just go into the header authenticiation, didn’t think about that! After that, all worked fine with that one error!
I have tried so much stuff that I lost a bit track of what I actually did. But in the end I managed to make it fully work, by following your mock data without the equal sign in front ( putting the json between {{ }} in the set node). Now, one last final step… I want to pass on different output data in that json file. But when I do somehow it doesnt work. This is probably the last missing link!