From a list of 1000 items, run a loop in batches of 100
![pachocastillosr](https://us.v-cdn.net/6037124/uploads/userpics/MC7ELS8NG1HC/nPLP98RNMYYEZ.jpg)
Hello,
I have a list of 1000 items and I have to run some functions for each one of them (on a loop) and finally upload all of them to an external database through an external api call.
The problem is this external database only allows to upload 100 items per api call so I can't wait until the 1000 loops are done and them upload all the items at once.
How can I upload them in batches of 100?
Best Answer
-
Ok so I'm not sure if this is the best solution, but what you can do is create an empty array outside the loop to which you will append your processed item and then you are checking if the array have already 100 items, if not, then the loops just continues, if yes then you are uploading them, clearing the array and move on with loop.
Answers
-
Note: Some times the list may be bigger or smaller than 1000 items.
-
Those items are in regular array that you get from somewhere else than Xano database or are you getting them via query from table?
-
@Pawel Magdanski in a regular array that I get from a Meta product catalog. Each variant_json is a product.
-
That seems interesting! I'm thinking, what if the list has 1001 items? Then the last item would not be uploaded because the final array didn't get to 100 items (it just got 1 item). @Pawel Magdanski
-
After the loop ends you can check if there is any items left in you array and if that's the case you are making the final upload.
-
@Pawel Magdanski got it! Thanks!
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback