Insert data to template to http endpoint

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

[{"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":[]}]

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

[{"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.]

1 Like

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