I have the HTTP Request Node result data in the form of an Array in the image below, how do I make the data loop to be entered into the MySQL database?
One array has several objects, the object variables can be seen in the image below.
thank you
I have the HTTP Request Node result data in the form of an Array in the image below, how do I make the data loop to be entered into the MySQL database?
One array has several objects, the object variables can be seen in the image below.
thank you
Dont loop. never loop if it can be avoided.
Add a split node after the http node - split on msg.data (or msg.payload.data or wherever data
is)
then feed the element object from the split node into a function node & generate your insert statement then pass it to the database.
How can a Function Node generate all looping data from a Split Node? can you make a simple example of a node? Thank you
demo...
output...
flow...
[{"id":"57591003.a97e3","type":"http in","z":"b872cb4b.5a6448","name":"","url":"/made/up/data","method":"get","upload":false,"swaggerDoc":"","x":370,"y":680,"wires":[["f5c022e8.24326"]]},{"id":"f5c022e8.24326","type":"function","z":"b872cb4b.5a6448","name":"make data","func":"msg.payload = {\n data : [\n {\n id: 1,\n name: \"fred\",\n age: 44\n }, {\n id: 2,\n name: \"tina\",\n age: 34\n }, {\n id: 3,\n name: \"harry\",\n age: 29\n }\n ]\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":680,"wires":[["69a01397.093ffc"]]},{"id":"69a01397.093ffc","type":"http response","z":"b872cb4b.5a6448","name":"","statusCode":"","headers":{},"x":750,"y":680,"wires":[]},{"id":"a443144.42059e8","type":"inject","z":"b872cb4b.5a6448","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":340,"y":740,"wires":[["ff2b5fe2.9e156"]]},{"id":"ff2b5fe2.9e156","type":"http request","z":"b872cb4b.5a6448","name":"get /made/up/data","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://localhost:1889/made/up/data","tls":"","persist":false,"proxy":"","authType":"","x":530,"y":740,"wires":[["d360fec9.c416","a87ec747.c64818"]]},{"id":"d8823d0f.2c83","type":"split","z":"b872cb4b.5a6448","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":950,"y":740,"wires":[["5eced342.f8026c","e50d8c47.36972"]]},{"id":"d360fec9.c416","type":"change","z":"b872cb4b.5a6448","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.data","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":740,"wires":[["d8823d0f.2c83"]]},{"id":"5eced342.f8026c","type":"function","z":"b872cb4b.5a6448","name":"make SQL","func":"msg.topic = `INSERT INTO table1 (id, name, age) VALUES (${msg.payload.id}, '${msg.payload.name}', ${msg.payload.age})`\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1110,"y":740,"wires":[["e168393f.855548"]]},{"id":"e168393f.855548","type":"debug","z":"b872cb4b.5a6448","name":"SQL","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"topic","statusType":"msg","x":1270,"y":740,"wires":[]},{"id":"e50d8c47.36972","type":"debug","z":"b872cb4b.5a6448","name":"split data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1070,"y":800,"wires":[]},{"id":"a87ec747.c64818","type":"debug","z":"b872cb4b.5a6448","name":"req data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":700,"y":800,"wires":[]}]
Thank you very much sir
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.