HTTP Request Node JSON payload

I have been using the http-request node successfully (including authentication of the device). I now want to send another command (payload) but due to how it is formatted do not get it working.

The call to be executed:

http://<IP>/rpc/Cover.SetConfig?id=0&config={in_mode:%22detached%22}

works like this when using a browser. So the call basically is correct.

In node red I'm calling the http-request node with the payload providing the data as params (works this way for other commands):

image

I get the following reply:

image

The issue here is that the config data is provided in {} which gets reformatted when sending this payload to the http-request node.

The config part should stay like config={in_mode:%22detached%22} and should not be formatted.

Any idea how to solve this? Any escape characters that I can use? I tried {{{}}}, \{\}, but nothing did the trick.

The simplest method would be to put it together in a function node (or template node)

Function e.g.

msg.url = 'http://<IP>/rpc/Cover.SetConfig?id=0&config={in_mode:%22detached%22}'
return msg

NOTE: for this to work, you need to leave the http url field blank.

Read the built in help for the http node for more info

I think I need to send the parameter as POST body together with the authentication, which is what I'm currently doing. But I suspect that the nested {} cause issues here.

I tried as you explained already, but it did not work. I think the authentication part was then not accepted anymore. I somehow need to send it as is in the params.

Not sure I follow.

If you are doing POST then simple put the JS object directly into msg.payload.

Are there other/additional data (different from this config and id you mention in The URL) that needs to be sent as POST data?

{in_mode:%22detached%22} in_mode would require quotes also.

If you post this then config would need to be a valid json or a javascript object
e.g

[{"id":"762043d30d717daa","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"url","v":"http://192.168.1.10/rpc/Cover.SetConfig","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":0,\"config\":{\"in_mode\":\"detached\"}}","payloadType":"json","x":170,"y":5000,"wires":[["c2242105fc8a2f0a"]]},{"id":"c2242105fc8a2f0a","type":"http request","z":"d1395164b4eec73e","name":"","method":"POST","ret":"txt","paytoqs":"query","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":330,"y":5000,"wires":[[]]}]
1 Like

@Steve-Mcl @E1cid

Thanks to both of you. I just tried what @E1cid mentioned and it seems to work.
Let me clean up my workflow with that and I will confirm.

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