Have large amounts of data in Google Sheets that you need to loop through but you’re not sure what is the best way import the data and then act on it? Then you’ve come to the right place! This post will show you how to use Zapier to loop through arrays imported from Google Sheets so that you can carry out actions in bulk for each of the array values as shown in the flow diagram below.
Get Text Arrays from Google Sheets
In this post we’ll use the Customer Database Google Sheet to send delivery notifications to customers if their order is scheduled for delivery today. As explained in the Zapier Google Sheets Quick-Start Guide, there are a few different ways to import data from Google Sheets into Zapier as arrays depending on the number of rows or the amount of data you are importing.
For this example, we will use a webhook to send the arrays from Google Sheets to Zapier as explained in the Zapier Import Multiple Rows from Google Sheets post. Then in our zap, we will use the “Catch Hook” trigger to receive the incoming webhook containing the array information.
Zapier Loop Through Array Workflow
Zapier Loop Through Array Action
Once the incoming array information has been received, it can then be used in the “Set up action” section of the “Create Loop from Text” action in the “Looping by Zapier” app. In the “Values To Loop” section, you can create a looping variable for each of your arrays and then specify the “Text Delimiter” so that Zapier can parse out all the array values to loop through.
N.B. One thing to bear in mind is that the maximum number of loop iterations that you can do using this loop through array action is 500. If you have more iterations to do than this then you will need to use nested looping (see the Zapier For Each Loop Quick-Start Guide).
After the “Values to Loop” have been setup, they can then be used in subsequent steps to supply a different value for that variable for each iteration of the loop.
Send Email for Each Array Value
Send SMS for Each Array Value
If you have not yet gotten yourself set up with Telnyx then take a look at the Marketo 2 Way SMS using Telnyx and Zapier post to see how to get started with sending SMS.
One thing to note about sending SMS is that there are rate limits that apply to certain number types so if you try and exceed these limits, which is very likely when you loop through arrays, then the carrier will throttle the messages and spread them out over a longer timespan to ensure delivery. Therefore, do not expect all your SMS to be delivered right away when looping.
This throttling is implemented to prevent fraudsters and bad actors from easily being able to spam people with large amounts of SMS at once. If higher rate limits are needed you can get verified by your carrier who can then increase your rate limit or allow you to purchase another number type with higher throughput e.g. a short code number. If you want to learn more about rate limits and the pros and cons of the different number types then take a look at the Marketo SMS Marketing with Telnyx post.
Post Loop Subsequent Actions
As shown in the flow diagram in the introduction, you can use a filter to stop looping so that actions after the filter will only run once. This is achieved by checking if the “Loop Iteration is Last” value from the loop through array action in Step 2 is TRUE.
Now that the Zap has progressed beyond the filter, a single summary email and SMS can be sent to a customer manager so that they can see all the customers who will receive deliveries today. Notice how the bodies of the email and SMS are using the array values from the webhook in Step 1 instead of the looping variables from Step 2. This is important because we want all the array values to be present in a single message, as shown in the SMS inbox image below.
N.B. You’ll notice from the image above and the screenshot of the SMS messages below that the emails and SMS messages do not get sent in the expected order. If the order that the for loop executes in is important to you and you need email 3 to be sent before email 6 then take a look at using webhooks or delays.
What’s After Looping Through Arrays?
There you have it! That is how you can use Zapier to loop through arrays imported from Google Sheets so that you can carry out actions in bulk for each array value.
This example used the “Create Loop from Text” action from the “Looping by Zapier” app. There are 2 more actions available that you can use for looping: “Create Loop from Line Items” and “Create Loop from Numbers”. These actions are covered, respectively, in the posts below:
If you are interested in nested looping within Zapier then take a look at the Zapier For Each Loop Quick-Start Guide.