# Insert data to template to http endpoint

**URL:** <https://discourse.nodered.org/t/insert-data-to-template-to-http-endpoint/46334>\
**Category:** General\
**Created:** [27 May 2021 11:08 UTC](https://discourse.nodered.org/t/insert-data-to-template-to-http-endpoint/46334 "2021-05-27T11:08:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ketpa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ketpa/32/42496_2.png) [@ketpa](https://discourse.nodered.org/u/ketpa)\
**Post date:** [27 May 2021 11:08 UTC](https://discourse.nodered.org/t/insert-data-to-template-to-http-endpoint/46334/1 "2021-05-27T11:08:22Z")

</div>

I want to get data from some json page, change it, and create endpoint

 ![obraz](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/db59a9c32cf26000aa9e9563368a3768b9e4c722.png)

```auto
[{"id":"16968f0f.405cd9","type":"inject","z":"f228441f.926208","name":"","repeat":"1","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":150,"y":1160,"wires":[["d6979ea8.12354"]]},{"id":"2c170cf8.84341c","type":"template","z":"f228441f.926208","name":"","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"<h1>This is the payload: {{msg.payload}} !</h1>","output":"str","x":700,"y":1220,"wires":[["c35e5f7f.36d8a"]]},{"id":"924084b1.5745b8","type":"http in","z":"f228441f.926208","name":"","url":"/json3","method":"get","upload":false,"swaggerDoc":"","x":160,"y":1220,"wires":[["fe8bdc7a.c2e828"]]},{"id":"c35e5f7f.36d8a","type":"http response","z":"f228441f.926208","name":"","statusCode":"","headers":{},"x":890,"y":1220,"wires":[]},{"id":"fe8bdc7a.c2e828","type":"function","z":"f228441f.926208","name":"","func":"msg.payload = msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":520,"y":1220,"wires":[["2c170cf8.84341c"]]},{"id":"d6979ea8.12354","type":"http request","z":"f228441f.926208","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://jsonplaceholder.typicode.com/todos/1","tls":"","persist":false,"proxy":"","authType":"","x":310,"y":1160,"wires":[["fe8bdc7a.c2e828","83edd019.9f32f"]]},{"id":"83edd019.9f32f","type":"debug","z":"f228441f.926208","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":1140,"wires":[]}]

```

---

<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:** [27 May 2021 11:40 UTC](https://discourse.nodered.org/t/insert-data-to-template-to-http-endpoint/46334/2 "2021-05-27T11:40:14Z")

</div>

Ok you have to make sure msg.res makes it to the response node, you can see it in the full debug.  
you can not inject direct to a http in / response, as msg.res will not be created, create a seperate http request node to test.  
example

```auto
[{"id":"924084b1.5745b8","type":"http in","z":"c74669a0.6a34f8","name":"","url":"/json3","method":"get","upload":false,"swaggerDoc":"","x":560,"y":4240,"wires":[["d6979ea8.12354"]]},{"id":"d6979ea8.12354","type":"http request","z":"c74669a0.6a34f8","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://jsonplaceholder.typicode.com/todos/1","tls":"","persist":false,"proxy":"","authType":"","x":760,"y":4240,"wires":[["83edd019.9f32f","2c170cf8.84341c"]]},{"id":"83edd019.9f32f","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":4140,"wires":[]},{"id":"2c170cf8.84341c","type":"template","z":"c74669a0.6a34f8","name":"","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"<h1>This is the payload: {{payload}} !</h1>","output":"str","x":970,"y":4240,"wires":[["c35e5f7f.36d8a"]]},{"id":"c35e5f7f.36d8a","type":"http response","z":"c74669a0.6a34f8","name":"","statusCode":"","headers":{},"x":1130,"y":4240,"wires":[]},{"id":"a4a79fd0.45b5d","type":"inject","z":"c74669a0.6a34f8","name":"enter your url/json3","props":[{"p":"url","v":"http://ip:1880/json3/","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":620,"y":4340,"wires":[["520c5306.059704"]]},{"id":"520c5306.059704","type":"http request","z":"c74669a0.6a34f8","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":860,"y":4340,"wires":[["a4ca1f30.700d68"]]},{"id":"a4ca1f30.700d68","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1080,"y":4340,"wires":[]}]

```

If you want the data in an object not a string , make sure the http request node is set to output a object. To reference the objects properties use payload.title in the template node. No msg on the front.  
[edit use triple {{{ }}} if you dont want the html entities replaced.]

---

<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:** [10 June 2021 11:40 UTC](https://discourse.nodered.org/t/insert-data-to-template-to-http-endpoint/46334/3 "2021-06-10T11:40:50Z")

</div>

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