# How to loop data from HTTP Request Node?

**URL:** https://discourse.nodered.org/t/how-to-loop-data-from-http-request-node/44012
**Category:** General
**Created:** [12 April 2021 04:19 UTC](https://discourse.nodered.org/t/how-to-loop-data-from-http-request-node/44012 "2021-04-12T04:19:48Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![marwinwijaya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marwinwijaya/32/23923_2.png) [@marwinwijaya](https://discourse.nodered.org/u/marwinwijaya)
#### Post date: [12 April 2021 04:19 UTC](https://discourse.nodered.org/t/how-to-loop-data-from-http-request-node/44012/1 "2021-04-12T04:19:48Z")

</div>

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?

 ![Screenshot_4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3f70f167b363214d6e10e3e5614caaaab3c44e82.png)

One array has several objects, the object variables can be seen in the image below.

 ![Screenshot_5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/e/1eddcff525d1c67d1e737299abc9681a64c5f813.png)

thank you

---

<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: [12 April 2021 07:02 UTC](https://discourse.nodered.org/t/how-to-loop-data-from-http-request-node/44012/2 "2021-04-12T07:02:07Z")

</div>

> [@marwinwijaya](#):
>
> how do I make the data loop to be entered into the MySQL database?

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.

---

<div class="post-metadata">

### Author: ![marwinwijaya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marwinwijaya/32/23923_2.png) [@marwinwijaya](https://discourse.nodered.org/u/marwinwijaya)
#### Post date: [19 April 2021 04:18 UTC](https://discourse.nodered.org/t/how-to-loop-data-from-http-request-node/44012/3 "2021-04-19T04:18:22Z")

</div>

How can a Function Node generate all looping data from a Split Node? can you make a simple example of a node? Thank you

---

<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: [19 April 2021 07:10 UTC](https://discourse.nodered.org/t/how-to-loop-data-from-http-request-node/44012/4 "2021-04-19T07:10:39Z")

</div>

demo...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/43a9d71a77876531f27c860e0eeb498f4c801fed.png)

output...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/7605eec17a7c018729de3f4e1b0eb80227383978.png)

flow...

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

```

---

<div class="post-metadata">

### Author: ![marwinwijaya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marwinwijaya/32/23923_2.png) [@marwinwijaya](https://discourse.nodered.org/u/marwinwijaya)
#### Post date: [16 June 2021 08:59 UTC](https://discourse.nodered.org/t/how-to-loop-data-from-http-request-node/44012/5 "2021-06-16T08:59:45Z")

</div>

Thank you very much sir

---

<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: [30 June 2021 09:00 UTC](https://discourse.nodered.org/t/how-to-loop-data-from-http-request-node/44012/6 "2021-06-30T09:00:32Z")

</div>

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