Explore all the ways to setup a Zapier for each loop using the 3 native “Looping by Zapier” actions or your own custom definitions within “Code by Zapier” actions in Python or Javascript and how you can overcome Zapier’s 500 iteration or 10 second timeout limits using nested loops.
Since all the examples linked to within this post either retrieve data from or manipulate data in Google Sheets, the Zapier Google Sheets Quick-Start Guide will show you the ropes you need to take the reins!
“Looping by Zapier” For Each Loop
The inbuilt “Looping by Zapier” app has three actions that enable you to do up to 500 iterations of all the actions contained within the loop. Unfortunately, Zapier say that the only way to get more than 500 iterations is to contact their support team to get your name added to the feature request so that you will be notified when their engineers release this feature.
Can’t wait that long?
Take a look at the “Code by Zapier” For Each Loop and Nested Zapier For Each Loop sections below to see how you can iterate like its 2008!
“Create Loop From Line Items”
When importing data from Google Sheets using the “Find Many Spreadsheet Rows (With Line Item Support)” action the data is returned in line item format where you get an array for each column in your sheet. The Zapier Loop Through Line Items Example post will show you how to use the “Create Loop from Line Items” action to loop through the row values contained within these arrays.
“Create Loop From Text”
If the values you want to loop through are contained within text variables then you can use the “Create Loop from Text” action, as is done in the Zapier Loop Through Array from Google Sheets post, to split your text variables into arrays of values that you can then iterate through to do things like sending a personalized SMS to each person in a Google Sheet.
“Create Loop From Numbers”
The third and final “Looping by Zapier” action allows you to use a number range to control the iterations of your Zapier for each loop. The Zapier Loop Action post walks you through how to use the “Create Loop From Numbers” action to update rows in a Google Sheet corresponding to the numbers within your custom defined number range.
Executing Loop Actions Sequentially
It is worth noting that the “Looping by Zapier” actions do not carry out the loop iterations sequentially. Instead, the loop action executes the iterations simultaneously and you cannot be guaranteed that the actions for iteration 0 will be carried out before the actions for iteration N.
As shown in the Zapier forum using the loop iteration number in the “Delay After Queue” action will mean that each successive iteration will be further delayed than the previous iteration i.e. the first iteration will be delayed for 1 minute before executing and the 2nd iteration will be delayed for 2 minutes before executing.
Therefore, we can get the iterations to execute sequentially as desired. It might take some experimentation to find the correct delay between iterations which is long enough so that one iteration is completely finished before the next one starts.
“Code by Zapier” For Each Loop
While the three “Looping by Zapier” actions are easy to configure they do have the limitation that you can only do 500 iterations at once. To circumvent this restriction you can build your Zapier for each loop into Python or Javascript code within a “Code by Zapier” action (as shown in the Zapier Nested Looping using Webhooks & Python post) with the added benefit that you now have the ability to completely customize what your loop does.
Beware though that each Zapier action has a 10 second timeout limit so if your Zapier for each loop code tries to do too many iterations at once and runs for more than 10 seconds then this “Code by Zapier” step will fail.
This is where nested loops in Zapier come in useful because you can put these “Code by Zapier” loops or “Looping by Zapier” actions within an outer loop so you can continue to iterate until all your jobs are complete.
Webhook For Each Loop
Another way to overcome the 500 iteration limit imposed by Zapier is to loop using webhooks. Before taking a look at the section below, which uses webhooks for nested looping, take a look at the Marketo Program Cloning Via API post to get a simpler example of how to use webhooks for looping in Zapier without the complexity of nested looping.
Nested Zapier For Each Loop
Nested loops in Zapier are powerful because they allow you to overcome the 500 iteration limit of the “Looping by Zapier” action or the 10 second timeout limit imposed when looping within “Code by Zapier” actions.
The nested Zapier for each loop is contained within an outer loop formed by a “Catch Webhook” trigger event at the start and a “Send Webhook” action at the end, which passes along the necessary information for the next iteration of the outer loop to continue from where the current iteration finished off.
The Zapier Nested Looping using Webhooks & Python post shows you how to nest a Python loop.
The Zapier Loop Array with Nesting posts shows you how to nest a “Looping by Zapier” action.
Zapier For Each Loop Follow Ups
Now that you know how to create a Zapier for each loop, you are ready to add more tools to your Zapier Swiss army knife! Take a look at the posts below to learn about other Zapier features and see how they can be applied in real-world examples.