HTTP Post command

Hey, my google powers is not enough and I havent really found a good explanation.

Can someone please tell me how I can send post request that looks like this?

curl -X POST -H "Content-Type: application/json" -d '{"percent":"+5"} http://127.0.0.1:80/api/volume

Should I use function block first and set the it to JSON.

Thanks in advance.

You could use a change node, function node or a template node, The http request node will accept the json data in object form so setting msg.payload .percent to "+5" should work which every node you wish to use.
e.g. using a inject node.

[{"id":"e3d6e970.e7768","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload.percent","v":"+5","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":3120,"wires":[["c62fdf0a.1924d8"]]},{"id":"c62fdf0a.1924d8","type":"http request","z":"bf9e1e33.030598","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://127.0.0.1:80/api/volume","tls":"","persist":false,"proxy":"","authType":"","x":430,"y":3120,"wires":[["af8c089c.a6fbe8"]]},{"id":"af8c089c.a6fbe8","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":3120,"wires":[]}]

[edit] added examples of function. change and template nodes.

[{"id":"e3d6e970.e7768","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"+5","payloadType":"str","x":130,"y":2920,"wires":[["ea6c0627.170ec","394d0823.2e2b1","3125445d.1e20e4"]]},{"id":"ea6c0627.170ec","type":"template","z":"bf9e1e33.030598","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"percent\": \"{{{payload}}}\"}","output":"json","x":300,"y":2920,"wires":[["af8c089c.a6fbe8"]]},{"id":"394d0823.2e2b1","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.percent","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":2980,"wires":[["af8c089c.a6fbe8"]]},{"id":"3125445d.1e20e4","type":"function","z":"bf9e1e33.030598","name":"","func":"msg.payload = {\"percent\": msg.payload};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":3040,"wires":[["af8c089c.a6fbe8"]]},{"id":"af8c089c.a6fbe8","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":720,"y":2920,"wires":[]}]
1 Like

Thanks it worked!
Since I'm very new to this is it possibly get a example of it on the the other nodes tried to get it to work using the other ones but it was not functional.

You might benefit from the official videos. I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

1 Like

Thanks, will do that.
I think that will be fit me a lot!

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