# Sending a body for http request outside the node

**URL:** <https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526>\
**Category:** General\
**Created:** [8 March 2022 09:42 UTC](https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526 "2022-03-08T09:42:07Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [8 March 2022 09:42 UTC](https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526/1 "2022-03-08T09:42:07Z")

</div>

Hi,

I want to send a http request but I need to send a body with it. This I want to do with a template node.  
But when I send it, it doesn't work.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c141ed16d9b3e0fd3277fe72a864a918b4099dc.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/a/1aeb96d3377d53c44e1b819f282db75d6e6dc3bf.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/7718be35123223978e84d6f2b0d57dce5500b787.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [8 March 2022 10:20 UTC](https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526/2 "2022-03-08T10:20:32Z")

</div>

You have not given enough info to give a definite answer, If this is a post request then the payload needs to be an object not a text string, try setting the template to output a object.

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [8 March 2022 10:25 UTC](https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526/3 "2022-03-08T10:25:59Z")

</div>

How do you mean?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [8 March 2022 10:26 UTC](https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526/4 "2022-03-08T10:26:33Z")

</div>

where is says output as.

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [8 March 2022 10:28 UTC](https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526/5 "2022-03-08T10:28:45Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/a/8a00893deb2c7f73962613e0f316e0e9318e3432.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/f/2f69731f282307efa3b6a74837be9d43901999ba.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [8 March 2022 10:31 UTC](https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526/6 "2022-03-08T10:31:11Z")

</div>

You did not show the mustache format in original post, all info is important

select format mustache, above where it says output.

```auto
[{"id":"3c2ab2fc9d965430","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $globalContext(\"UserMatrix[5][1]\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":1480,"wires":[["2817e15eff895b41","7e817af038cbae64"]]},{"id":"c0935bad310557da","type":"template","z":"bf9e1e33.030598","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"mode\": \"NORMAL\",\"limit\": {\"unit\": \"PERCENTAGE\", \"value\": {{payload}}}}\n\n","output":"json","x":280,"y":1480,"wires":[["3c2ab2fc9d965430"]]},{"id":"2817e15eff895b41","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":1560,"wires":[]},{"id":"7e817af038cbae64","type":"http request","z":"bf9e1e33.030598","name":"Laadpaal sturen %","method":"PUT","ret":"txt","paytoqs":"body","url":"https://app1pub.smappee.net/dev/v3/chargingstations/6000000046/connectors/1/mode","tls":"","persist":false,"proxy":"","authType":"","x":770,"y":1480,"wires":[["2817e15eff895b41"]]},{"id":"a368235a87847f26","type":"ui_slider","z":"bf9e1e33.030598","name":"","label":"Laadpercentage","tooltip":"","group":"58d1cfd1a2aec4cf","order":4,"width":3,"height":1,"passthru":true,"outs":"end","topic":"laadpercentage","min":0,"max":"100","step":"10","x":100,"y":1480,"wires":[["c0935bad310557da"]]},{"id":"dc6b3fb7.f44678","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":1480,"wires":[["c0935bad310557da"]]},{"id":"58d1cfd1a2aec4cf","type":"ui_group","name":"Connector 1","tab":"56b7e433f1483e4d","order":1,"disp":true,"width":"6","collapse":false},{"id":"56b7e433f1483e4d","type":"ui_tab","name":"Laadpalen sturen","icon":"dashboard","order":10,"disabled":false,"hidden":true}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 March 2022 10:32 UTC](https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526/7 "2022-03-08T10:32:21Z")

</div>

is payload a number? a string?

Use a debug node BEFORE the template node to check the value of `msg.payload`

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [8 March 2022 10:34 UTC](https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526/8 "2022-03-08T10:34:59Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/93045ec6d23045da62cb408df06e6d3127b65ddc.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 March 2022 10:38 UTC](https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526/9 "2022-03-08T10:38:13Z")

</div>

that looks normal. something else must be wrong.

Can you share your flow (only the parts that matter)

PS, sending screenshots of JSON is not good for us to help you (as we cannot copy & paste screenshots into a code editor to check)

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [8 March 2022 10:44 UTC](https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526/10 "2022-03-08T10:44:03Z")

</div>

This is my flow, I think that you need the token: a733c03b-a21e-3d95-94f1-ecf782696280

```auto
[{"id":"2817e15eff895b41","type":"debug","z":"fd77b4dafda3312f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":300,"wires":[]},{"id":"7e817af038cbae64","type":"http request","z":"fd77b4dafda3312f","name":"Laadpaal sturen %","method":"PUT","ret":"txt","paytoqs":"body","url":"https://app1pub.smappee.net/dev/v3/chargingstations/6000000046/connectors/1/mode","tls":"","persist":false,"proxy":"","authType":"","senderr":true,"credentials":{},"x":770,"y":300,"wires":[["2817e15eff895b41"]]},{"id":"3c2ab2fc9d965430","type":"change","z":"fd77b4dafda3312f","name":"","rules":[{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $globalContext(\"UserMatrix[5][1]\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":300,"wires":[["7e817af038cbae64"]]},{"id":"c0935bad310557da","type":"template","z":"fd77b4dafda3312f","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"{\"mode\": \"NORMAL\",\"limit\": {\"unit\": \"PERCENTAGE\", \"value\": {{msg.payload}}}}\n\n","output":"str","x":280,"y":300,"wires":[["3c2ab2fc9d965430"]]},{"id":"a368235a87847f26","type":"ui_slider","z":"fd77b4dafda3312f","name":"","label":"Laadpercentage","tooltip":"","group":"58d1cfd1a2aec4cf","order":4,"width":3,"height":1,"passthru":true,"outs":"end","topic":"laadpercentage","min":0,"max":"100","step":"10","x":100,"y":300,"wires":[["c0935bad310557da","80082c6a63545408"]]},{"id":"58d1cfd1a2aec4cf","type":"ui_group","name":"Connector 1","tab":"56b7e433f1483e4d","order":1,"disp":true,"width":"6","collapse":false},{"id":"56b7e433f1483e4d","type":"ui_tab","name":"Laadpalen sturen","icon":"dashboard","order":10,"disabled":false,"hidden":true}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 March 2022 11:04 UTC](https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526/11 "2022-03-08T11:04:51Z")

</div>

Here you go...

```auto
[{"id":"2817e15eff895b41","type":"debug","z":"c2233fc1d8cc5c3b","name":"Success (200)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1520,"y":800,"wires":[]},{"id":"7e817af038cbae64","type":"http request","z":"c2233fc1d8cc5c3b","name":"Laadpaal sturen %","method":"PUT","ret":"txt","paytoqs":"body","url":"https://app1pub.smappee.net/dev/v3/chargingstations/6000000046/connectors/1/mode","tls":"","persist":false,"proxy":"","authType":"","senderr":true,"x":1130,"y":840,"wires":[["01741bf269003147"]]},{"id":"3c2ab2fc9d965430","type":"change","z":"c2233fc1d8cc5c3b","name":"","rules":[{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer a733c03b-a21e-3d95-94f1-ecf782696280\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":840,"wires":[["7e817af038cbae64","9443b01bae04a5f3"]]},{"id":"a368235a87847f26","type":"ui_slider","z":"c2233fc1d8cc5c3b","name":"","label":"Laadpercentage","tooltip":"","group":"58d1cfd1a2aec4cf","order":4,"width":3,"height":1,"passthru":true,"outs":"end","topic":"laadpercentage","min":0,"max":"100","step":"10","x":460,"y":840,"wires":[["afb2087fedf6d848"]]},{"id":"11b2d6767a37219f","type":"debug","z":"c2233fc1d8cc5c3b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":920,"wires":[]},{"id":"9443b01bae04a5f3","type":"debug","z":"c2233fc1d8cc5c3b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1078,"y":905,"wires":[]},{"id":"17aa846d816458e9","type":"inject","z":"c2233fc1d8cc5c3b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":470,"y":900,"wires":[["afb2087fedf6d848"]]},{"id":"8f716df58bff1065","type":"inject","z":"c2233fc1d8cc5c3b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":480,"y":940,"wires":[["afb2087fedf6d848"]]},{"id":"afb2087fedf6d848","type":"function","z":"c2233fc1d8cc5c3b","name":"","func":"msg.payload = { \n \"mode\": \"NORMAL\", \n \"limit\": { \n \"unit\": \"PERCENTAGE\", \n \"value\": msg.payload \n }\n}\nconst UserMatrix = global.get(\"UserMatrix\");\n\n//enable next line to use global UserMatrix\n//const token = UserMatrix[5][1];\n\n//delete next line to use global UserMatrix\nconst token = \"a733c03b-a21e-3d95-94f1-ecf782696280\"\n\n\nmsg.headers = {\n Authorization: `Bearer ${token}`\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":840,"wires":[["3c2ab2fc9d965430","11b2d6767a37219f"]]},{"id":"01741bf269003147","type":"switch","z":"c2233fc1d8cc5c3b","name":"","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1330,"y":840,"wires":[["2817e15eff895b41"],["97e0aec4dbb32104"]]},{"id":"97e0aec4dbb32104","type":"debug","z":"c2233fc1d8cc5c3b","name":"Problem - check msg.statusCode","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1580,"y":860,"wires":[]},{"id":"58d1cfd1a2aec4cf","type":"ui_group","name":"Connector 1","tab":"56b7e433f1483e4d","order":1,"disp":true,"width":"6","collapse":false},{"id":"56b7e433f1483e4d","type":"ui_tab","name":"Laadpalen sturen","icon":"dashboard","order":10,"disabled":false,"hidden":true}]

```

Be sure to check inside the function node.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [22 March 2022 11:05 UTC](https://discourse.nodered.org/t/sending-a-body-for-http-request-outside-the-node/59526/12 "2022-03-22T11:05:16Z")

</div>

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