Loop through x amount of API pulls after 2s second delay each time

Hi,

I'd like to loop a request that polls an API a set amount of times, with having to create the nodes for each loop.

Currently everything works correctly just that if I want to add an additional page of results I have to copy+paste the nodes, which after 75 pages worth of API pulls my flow is quite large!

The first request is to

"https://www.website.com/?orderBy=_info/lastUpdated desc&pagesize=1000&page=1"

and the next one would be for example

"https://www.website.com/?orderBy=_info/lastUpdated desc&pagesize=1000&page=2"

image

[{"id":"94cd81fb54165be1","type":"inject","z":"cf5f51c0ab747382","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"headers","v":"{\"clientid\":\"dfedb32c-0995-45ce-9fa2-835c7a3d98a0\",\"Content-Type\":\"application/json\"}","vt":"json"}],"repeat":"","crontab":"50 23 * * 0","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":200,"wires":[["ad99126195072689","468652dfc704b451"]]},{"id":"ad99126195072689","type":"delay","z":"cf5f51c0ab747382","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":240,"y":240,"wires":[["5a1a1eb5e2cd2d6a","658e7b633b95fa01"]]},{"id":"5a1a1eb5e2cd2d6a","type":"delay","z":"cf5f51c0ab747382","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":240,"y":280,"wires":[["5968c09367d877f8"]]},{"id":"468652dfc704b451","type":"function","z":"cf5f51c0ab747382","name":"","func":"msg.url = \"https://www.website.com/?orderBy=_info/lastUpdated desc&pagesize=1000&page=1\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":200,"wires":[["ed1585cf1dea324b"]]},{"id":"658e7b633b95fa01","type":"function","z":"cf5f51c0ab747382","name":"","func":"msg.url = \"https://www.website.com/?orderBy=_info/lastUpdated desc&pagesize=1000&page=2\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":240,"wires":[["d899fde25fe99796"]]},{"id":"5968c09367d877f8","type":"function","z":"cf5f51c0ab747382","name":"","func":"msg.url = \"https://www.website.com/?orderBy=_info/lastUpdated desc&pagesize=1000&page=3\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":280,"wires":[["602c8e3fb3410b31"]]},{"id":"ed1585cf1dea324b","type":"http request","z":"cf5f51c0ab747382","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":630,"y":200,"wires":[[]]},{"id":"d899fde25fe99796","type":"http request","z":"cf5f51c0ab747382","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":630,"y":240,"wires":[[]]},{"id":"602c8e3fb3410b31","type":"http request","z":"cf5f51c0ab747382","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":630,"y":280,"wires":[[]]}]

Is there an elegant way to do this a set amount of times?

Something like this maybe

[{"id":"94cd81fb54165be1","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"url","v":"https://www.website.com/?orderBy=_info/lastUpdated desc&pagesize=1000&page=","vt":"str"},{"p":"topic","vt":"str"},{"p":"headers","v":"{\"clientid\":\"dfedb32c-0995-45ce-9fa2-835c7a3d98a0\",\"Content-Type\":\"application/json\"}","vt":"json"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,2,3]","payloadType":"json","x":170,"y":2140,"wires":[["84035131.076c7"]]},{"id":"84035131.076c7","type":"split","z":"bf9e1e33.030598","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":290,"y":2140,"wires":[["5a1a1eb5e2cd2d6a"]]},{"id":"5a1a1eb5e2cd2d6a","type":"delay","z":"bf9e1e33.030598","name":"","pauseType":"rate","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":250,"y":2180,"wires":[["77214bac.71cd5c"]]},{"id":"77214bac.71cd5c","type":"template","z":"bf9e1e33.030598","name":"","field":"url","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{{url}}}{{{payload}}}","output":"str","x":440,"y":2180,"wires":[["ed1585cf1dea324b"]]},{"id":"ed1585cf1dea324b","type":"http request","z":"bf9e1e33.030598","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":680,"y":2180,"wires":[["d33d7ed3.b878"]]},{"id":"d33d7ed3.b878","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":340,"y":2240,"wires":[]}]

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