I want to create a http request and the get a desired json file output. I have done the following this and I am getting a timeout error while running please help.
The flow is as follows:
[{"id":"2e661d86.fa8792","type":"http in","z":"b53fc322.1dcb7","name":"/time","url":"/time","method":"get","upload":false,"swaggerDoc":"","x":130,"y":280,"wires":[["8cd25dc8.9a8d9"]]},{"id":"8cd25dc8.9a8d9","type":"function","z":"b53fc322.1dcb7","name":"Time","func":"var d = new Date(); // for now\nvar hour = d.getHours(); // => 9\nvar min = d.getMinutes(); // => 30\nif(hour < 10){\n hour = '0' + hour\n}\nif(min < 10){\n min = '0'+ min\n}\nmsg.payload = {'hours':hour,\n 'minutes':min}\nreturn msg","outputs":1,"noerr":0,"x":300,"y":280,"wires":[["4205f606.514958"]]},{"id":"4205f606.514958","type":"template","z":"b53fc322.1dcb7","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Time last server time request received at {{payload.hours}}:{{payload.minutes}}\n","output":"json","x":460,"y":280,"wires":[["bf8f7c07.8cea1"]]},{"id":"bf8f7c07.8cea1","type":"function","z":"b53fc322.1dcb7","name":"Header","func":"// If sending JSON data the content type is:\n//msg.headers={"Content-Type":"application/json"}\n\n// For HTML use the content type line below:\nmsg.headers={"Content-Type":"text/html"}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":280,"wires":[["2e1c54e0.51a52c"]]},{"id":"2e1c54e0.51a52c","type":"http response","z":"b53fc322.1dcb7","name":"","statusCode":"","headers":{},"x":800,"y":280,"wires":},{"id":"3e0356fa.dc088a","type":"http in","z":"b53fc322.1dcb7","name":"/random","url":"/random","method":"get","upload":false,"swaggerDoc":"","x":140,"y":360,"wires":[["d5c3b5fb.4cd768"]]},{"id":"d5c3b5fb.4cd768","type":"function","z":"b53fc322.1dcb7","name":"Random","func":"rnd = Math.round(Math.random() *100)\nvar d1 = new Date(); // for now\nvar hour1 = d1.getHours(); // => 9\nvar min1 = d1.getMinutes(); // => 30\nif(hour1 < 10){\n hour1 = '0' + hour1\n}\nif(min1 < 10){\n min1 = '0'+ min1\n}\nmsg.payload = {'random':rnd,\n 'hours':hour1,\n 'minutes':min1\n}\nreturn msg","outputs":1,"noerr":0,"x":300,"y":360,"wires":[["6c6d5d0f.ef2a54","422c7eb5.4e99a"]]},{"id":"6c6d5d0f.ef2a54","type":"template","z":"b53fc322.1dcb7","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Last random number request returned {{payload.random}}\n","output":"json","x":460,"y":360,"wires":[["54aad7da.b41ce8"]]},{"id":"54aad7da.b41ce8","type":"function","z":"b53fc322.1dcb7","name":"Header","func":"// If sending JSON data the content type is:\n//msg.headers={"Content-Type":"application/json"}\n\n// For HTML use the content type line below:\nmsg.headers={"Content-Type":"text/html"}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":360,"wires":[["7e5ccc8d.b85784"]]},{"id":"7e5ccc8d.b85784","type":"http response","z":"b53fc322.1dcb7","name":"","statusCode":"","headers":{},"x":800,"y":360,"wires":},{"id":"572d0a8c.5f80b4","type":"http in","z":"b53fc322.1dcb7","name":"/page","url":"/page","method":"get","upload":false,"swaggerDoc":"","x":130,"y":420,"wires":[["3d6981a7.3cd1fe"]]},{"id":"3d6981a7.3cd1fe","type":"function","z":"b53fc322.1dcb7","name":"Page","func":"rnd = Math.round(Math.random() *100)\nvar d = new Date(); // for now\nvar hour = d.getHours(); // => 9\nvar min = d.getMinutes(); // => 30\nif(hour < 10){\n hour = '0' + hour\n}\nif(min < 10){\n min = '0'+ min\n}\nmsg.payload = {'hours':hour,\n 'minutes':min,\n 'random':rnd\n}\nreturn msg","outputs":1,"noerr":0,"x":300,"y":420,"wires":[["422c7eb5.4e99a"]]},{"id":"422c7eb5.4e99a","type":"template","z":"b53fc322.1dcb7","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Time last server time request received at {{payload.hours}}:{{payload.minutes}}\nLast random number request returned {{payload.random}}, which was received at {{payload.hours}}:{{payload.minutes}}\n","output":"json","x":460,"y":420,"wires":[["bc5cd986.75d568"]]},{"id":"bc5cd986.75d568","type":"function","z":"b53fc322.1dcb7","name":"Header","func":"// If sending JSON data the content type is:\n//msg.headers={"Content-Type":"application/json"}\n\n// For HTML use the content type line below:\nmsg.headers={"Content-Type":"text/html"}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":420,"wires":[["d686f052.15c9f"]]},{"id":"d686f052.15c9f","type":"http response","z":"b53fc322.1dcb7","name":"","statusCode":"","headers":{},"x":800,"y":420,"wires":}]
- fix your flow - see How to share code or flow json
- what platform - i.e.os and release
- what version of NR and node.js
- what 'contrib' nodes are you using? i.e. node-red-contrib-xxxxxxxx
I want to create a http request and the get a desired json file output. I have done the following this and I am getting a timeout error while running please help.
The flow is as follows:
[{"id":"2e661d86.fa8792","type":"http in","z":"b53fc322.1dcb7","name":"/time","url":"/time","method":"get","upload":false,"swaggerDoc":"","x":130,"y":280,"wires":[["8cd25dc8.9a8d9"]]},{"id":"8cd25dc8.9a8d9","type":"function","z":"b53fc322.1dcb7","name":"Time","func":"var d = new Date(); // for now\nvar hour = d.getHours(); // => 9\nvar min = d.getMinutes(); // => 30\nif(hour < 10){\n hour = '0' + hour\n}\nif(min < 10){\n min = '0'+ min\n}\nmsg.payload = {'hours':hour,\n 'minutes':min}\nreturn msg","outputs":1,"noerr":0,"x":300,"y":280,"wires":[["4205f606.514958"]]},{"id":"4205f606.514958","type":"template","z":"b53fc322.1dcb7","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Time last server time request received at {{payload.hours}}:{{payload.minutes}}\n","output":"json","x":460,"y":280,"wires":[["bf8f7c07.8cea1"]]},{"id":"bf8f7c07.8cea1","type":"function","z":"b53fc322.1dcb7","name":"Header","func":"// If sending JSON data the content type is:\n//msg.headers={"Content-Type":"application/json"}\n\n// For HTML use the content type line below:\nmsg.headers={"Content-Type":"text/html"}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":280,"wires":[["2e1c54e0.51a52c"]]},{"id":"2e1c54e0.51a52c","type":"http response","z":"b53fc322.1dcb7","name":"","statusCode":"","headers":{},"x":800,"y":280,"wires":},{"id":"3e0356fa.dc088a","type":"http in","z":"b53fc322.1dcb7","name":"/random","url":"/random","method":"get","upload":false,"swaggerDoc":"","x":140,"y":360,"wires":[["d5c3b5fb.4cd768"]]},{"id":"d5c3b5fb.4cd768","type":"function","z":"b53fc322.1dcb7","name":"Random","func":"rnd = Math.round(Math.random() *100)\nvar d1 = new Date(); // for now\nvar hour1 = d1.getHours(); // => 9\nvar min1 = d1.getMinutes(); // => 30\nif(hour1 < 10){\n hour1 = '0' + hour1\n}\nif(min1 < 10){\n min1 = '0'+ min1\n}\nmsg.payload = {'random':rnd,\n 'hours':hour1,\n 'minutes':min1\n}\nreturn msg","outputs":1,"noerr":0,"x":300,"y":360,"wires":[["6c6d5d0f.ef2a54","422c7eb5.4e99a"]]},{"id":"6c6d5d0f.ef2a54","type":"template","z":"b53fc322.1dcb7","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Last random number request returned {{payload.random}}\n","output":"json","x":460,"y":360,"wires":[["54aad7da.b41ce8"]]},{"id":"54aad7da.b41ce8","type":"function","z":"b53fc322.1dcb7","name":"Header","func":"// If sending JSON data the content type is:\n//msg.headers={"Content-Type":"application/json"}\n\n// For HTML use the content type line below:\nmsg.headers={"Content-Type":"text/html"}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":360,"wires":[["7e5ccc8d.b85784"]]},{"id":"7e5ccc8d.b85784","type":"http response","z":"b53fc322.1dcb7","name":"","statusCode":"","headers":{},"x":800,"y":360,"wires":},{"id":"572d0a8c.5f80b4","type":"http in","z":"b53fc322.1dcb7","name":"/page","url":"/page","method":"get","upload":false,"swaggerDoc":"","x":130,"y":420,"wires":[["3d6981a7.3cd1fe"]]},{"id":"3d6981a7.3cd1fe","type":"function","z":"b53fc322.1dcb7","name":"Page","func":"rnd = Math.round(Math.random() *100)\nvar d = new Date(); // for now\nvar hour = d.getHours(); // => 9\nvar min = d.getMinutes(); // => 30\nif(hour < 10){\n hour = '0' + hour\n}\nif(min < 10){\n min = '0'+ min\n}\nmsg.payload = {'hours':hour,\n 'minutes':min,\n 'random':rnd\n}\nreturn msg","outputs":1,"noerr":0,"x":300,"y":420,"wires":[["422c7eb5.4e99a"]]},{"id":"422c7eb5.4e99a","type":"template","z":"b53fc322.1dcb7","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Time last server time request received at {{payload.hours}}:{{payload.minutes}}\nLast random number request returned {{payload.random}}, which was received at {{payload.hours}}:{{payload.minutes}}\n","output":"json","x":460,"y":420,"wires":[["bc5cd986.75d568"]]},{"id":"bc5cd986.75d568","type":"function","z":"b53fc322.1dcb7","name":"Header","func":"// If sending JSON data the content type is:\n//msg.headers={"Content-Type":"application/json"}\n\n// For HTML use the content type line below:\nmsg.headers={"Content-Type":"text/html"}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":420,"wires":[["d686f052.15c9f"]]},{"id":"d686f052.15c9f","type":"http response","z":"b53fc322.1dcb7","name":"","statusCode":"","headers":{},"x":800,"y":420,"wires":}]
System Windows10 but on Bluemix platform of IoT
version v10.15.1
and what does contrib mean and how do I check it??
@Umang please re-export your flow and share it again. The original one you shared is not valid json, and I guess you copy and pasted it when reposting it - so it's still invalid.
A quick scan through your flow json I can see it is only use default nodes, so don't worry about the contrib
question.
[{"id":"2e661d86.fa8792","type":"http in","z":"b53fc322.1dcb7","name":"/time","url":"/time","method":"get","upload":false,"swaggerDoc":"","x":130,"y":220,"wires":[["8cd25dc8.9a8d9"]]},{"id":"8cd25dc8.9a8d9","type":"function","z":"b53fc322.1dcb7","name":"Time","func":"var d = new Date(); // for now\nvar hour = d.getHours(); // => 9\nvar min = d.getMinutes(); // => 30\nif(hour < 10){\n hour = '0' + hour\n}\nif(min < 10){\n min = '0'+ min\n}\nmsg.payload = {'hours':hour,\n 'minutes':min}\nreturn msg","outputs":1,"noerr":0,"x":300,"y":220,"wires":[["4205f606.514958"]]},{"id":"4205f606.514958","type":"template","z":"b53fc322.1dcb7","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Time last server time request received at {{payload.hours}}:{{payload.minutes}}\n","output":"str","x":460,"y":220,"wires":[["bf8f7c07.8cea1"]]},{"id":"bf8f7c07.8cea1","type":"function","z":"b53fc322.1dcb7","name":"Header","func":"// If sending JSON data the content type is:\n//msg.headers={\"Content-Type\":\"application/json\"}\n\n// For HTML use the content type line below:\nmsg.headers={\"Content-Type\":\"application/json\"}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":220,"wires":[["2e1c54e0.51a52c"]]},{"id":"2e1c54e0.51a52c","type":"http response","z":"b53fc322.1dcb7","name":"","statusCode":"","headers":{},"x":800,"y":220,"wires":[]},{"id":"3e0356fa.dc088a","type":"http in","z":"b53fc322.1dcb7","name":"/random","url":"/random","method":"get","upload":false,"swaggerDoc":"","x":140,"y":300,"wires":[["d5c3b5fb.4cd768"]]},{"id":"d5c3b5fb.4cd768","type":"function","z":"b53fc322.1dcb7","name":"Random","func":"rnd = Math.round(Math.random() *100)\nvar d1 = new Date(); // for now\nvar hour1 = d1.getHours(); // => 9\nvar min1 = d1.getMinutes(); // => 30\nif(hour1 < 10){\n hour1 = '0' + hour1\n}\nif(min1 < 10){\n min1 = '0'+ min1\n}\nmsg.payload = {'random':rnd,\n 'hours':hour1,\n 'minutes':min1\n}\nreturn msg","outputs":1,"noerr":0,"x":300,"y":300,"wires":[["6c6d5d0f.ef2a54","422c7eb5.4e99a"]]},{"id":"6c6d5d0f.ef2a54","type":"template","z":"b53fc322.1dcb7","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Last random number request returned {{payload.random}}\n","output":"str","x":460,"y":300,"wires":[["728ae10a.d4914"]]},{"id":"7e5ccc8d.b85784","type":"http response","z":"b53fc322.1dcb7","name":"","statusCode":"","headers":{},"x":800,"y":300,"wires":[]},{"id":"572d0a8c.5f80b4","type":"http in","z":"b53fc322.1dcb7","name":"/page","url":"/page","method":"get","upload":false,"swaggerDoc":"","x":130,"y":360,"wires":[["3d6981a7.3cd1fe"]]},{"id":"3d6981a7.3cd1fe","type":"function","z":"b53fc322.1dcb7","name":"Page","func":"rnd = Math.round(Math.random() *100)\nvar d = new Date(); // for now\nvar hour = d.getHours(); // => 9\nvar min = d.getMinutes(); // => 30\nif(hour < 10){\n hour = '0' + hour\n}\nif(min < 10){\n min = '0'+ min\n}\nmsg.payload = {'hours':hour,\n 'minutes':min,\n 'random':rnd\n}\nreturn msg","outputs":1,"noerr":0,"x":300,"y":360,"wires":[["422c7eb5.4e99a"]]},{"id":"422c7eb5.4e99a","type":"template","z":"b53fc322.1dcb7","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Time last server time request received at {{payload.hours}}:{{payload.minutes}}\nLast random number request returned {{payload.random}}, which was received at {{payload.hours}}:{{payload.minutes}}\n","output":"str","x":460,"y":360,"wires":[["bc5cd986.75d568"]]},{"id":"bc5cd986.75d568","type":"function","z":"b53fc322.1dcb7","name":"Header","func":"// If sending JSON data the content type is:\n//msg.headers={\"Content-Type\":\"application/json\"}\n\n// For HTML use the content type line below:\nmsg.headers={\"Content-Type\":\"application/json\"}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":360,"wires":[["d686f052.15c9f"]]},{"id":"d686f052.15c9f","type":"http response","z":"b53fc322.1dcb7","name":"","statusCode":"","headers":{},"x":800,"y":360,"wires":[]},{"id":"728ae10a.d4914","type":"function","z":"b53fc322.1dcb7","name":"Header","func":"// If sending JSON data the content type is:\n//msg.headers={\"Content-Type\":\"application/json\"}\n\n// For HTML use the content type line below:\nmsg.headers={\"Content-Type\":\"application/json\"}\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":300,"wires":[["7e5ccc8d.b85784"]]}]
Well all your flows run fine on my local machine, so it could be a bluemix issue...
Actually now I am getting an error of Unexpected token T in JSON at position 0. I am needed to return a JSON document. So whats this Error I have no experience in JSON??
Sir, this question is a part of task on Coursera course. But I am unable to get replies there So could you just help me a little.
Thanks for sharing your flow.
Yes, I see this is the Coursera assignment you've shared. Please remember the honour code you signed on joining the course regarding sharing solutions online.
You don't say where you hit that error, so I'm not sure how we can help.
The grader output shows following output as an error:
Testing /page first load : SyntaxError: Unexpected token T in JSON at position 0.
Testing /time : SyntaxError: Unexpected token T in JSON at position 0.
Testing /random : SyntaxError: Unexpected token L in JSON at position 0