Can't set Header parameter with JSON value

Hi,

For a Post request to an API I need to sent a RAW JSON body. Which is no problem of course. Except for the fact that the header also changes to RAW when doing this in the HTTP node.

With Postman I can POST just fine for this API. But with n8n I am struggeling.

The Header is:
key = data
value = { “POSUniqueID”: “futurepos”, “ClientID”: “@(&#&@#&^@#", “Hash”: "@(&#($)&(#$” }

I tested it with pipedream, which gives a clear difference.

Testing with postman it looks like this:
image

With n8n I get:

I hope My question is clear enough and someone can help me with this. If more information is needed, please let me know.

Hi @Bram_Knuever,

Is that value what you are putting into the header or is it coming from another Node?

Hi @jon
For testing purposes I am directly inputting it in the http node. Later it would be coming from a different node.

Can you share the expression you use in the header value? Can you try doing it like in the example below?

Hi @Bram_Knuever,

That is interesting, I did a quick test here and it appears to be ok.

I didn’t bother with the expression editor with mine either, What version of n8n are you running?

1 Like

I tried a lot of stuff before but the most basic one is:
{“data”:{ “POSUniqueID”: “futurepos”, “ClientID”: “^%&&%&", “Hash”: "&%&^%(” }}

So the trouble seems to be with the RAW mode using normal header parameters is no issue.

Hope I made the issue more clear like this.

Version: 0.134.0

Ah yeah I have reproduced it, Looks like it is unhappy with it. I have the JSON.stringify() a go but hit an issue with the content-type.

Might need one of the smart n8n folk to work it out, Could need a tweak to the HTTP Node to get that working.

Thanks for trying anyways. :slight_smile:

Have been stuck on this all day. Hope someone knows how to fix this.

So it looks like this will do the job but it isn’t pretty, You basically need to treat the data value as a string rather than as JSON as the json parser kicks in and makes it an object instead of doing the other option which would be to create multiple headers to match the JSON.

Give this a bash…

{"data":"{\"POSUniqueID\": \"futurepos\", \"ClientID\": \"^%&&%&\", \"Hash\": \"&%&^%\"}"}

It looks to be running ok from here so should get you up and running :slightly_smiling_face:

I don’t like being defeated… Now I am going to go cook dinner :+1:

2 Likes

awesome, this works. Thanks alot.
Have a nice dinner.

I am pretty sure I tried something like this, think I didn’t use the correct escaping. I think I did something like:
{"data":\"{\"POSUniqueID\": \"futurepos\", \"ClientID\": \"^%&&%&\", \"Hash\": \"&%&^%\"}\"}

which would mean 2 escapes too many :frowning:

Need to fix this with the data from other nodes now, but I guess that wouldnt be a problem. Something to do tomorrow.

Thanks again.

If anyone else has a more elegant solution it is of course welcome. :slight_smile:

2 Likes