Looping Through Arrays, Numbers, or Text in Zapier

In this tutorial, we'll show you how to create loops in Zapier step by step. With a loop, you can run identical automated actions for every item in a dataset, even if you don't know exactly how large the dataset will be.

Written by
Matt Jasinski
and
Tom Nassr

October 28, 2024

Loops are one of the most powerful tools available to low-code builders. They allow you to process every item in a dataset individually—whether you're working with 5 items or 500—without adding redundant actions to your automation. In this guide, we'll walk through everything you need to know about creating and using loops in Zapier.

Prerequisites

Before we dive in, note that you'll need:

• A Zapier Pro plan or higher to publish Zaps with loops

• At least one trigger step in your Zap (loops can't be used as triggers)

• Optional: Any additional actions or search steps to collect data for your loop

Creating a loop from line items

Summary of steps

1. Add a new action to your Zap

2. Select "Looping by Zapier"

3. Choose "Create Loop from Line Items"

4. Add your value sets:

   • Select the fields you want to loop through

   • Give each value set a descriptive title

   • Add as many value sets as needed for your automation

5. Optional: Set a limit for iterations (maximum 500)

6. Test your loop to preview the structure

Adding a loop to your Zap

To add a loop to your Zap, add a new action, and select “Looping by Zapier”. 

Choose how you want to create the loop. You can choose to create a loop from line items, text, or numbers.

We’ll explain how text and number loops work later in this tutorial, but we’ll begin with a line item loop. 

Understanding Line Items

In Zapier (and JSON), line items are objects that contain arrays (lists) of other objects. You'll find line items in many common applications:


• Shopping cart items in Shopify orders

• Database records with multi-select fields

• Linked records in Airtable

Many datasets that you work with will be formatted with line items already, but you can also convert data into line items if needed. You can learn more about converting data into line items in Zapier’s help docs. 

Add value sets to your loop

Whatever you choose as your data source, you’ll need to provide at least one value set to loop through. A “value set” represents a field that your loop will process. 

Click on “Add value set” to add a new set to your loop. 

In our example, we’ll create value sets for the “Name”, “Task Count”, and “Slack ID” fields. All of these fields will be retrieved from the Airtable search step that precedes our loop. 

You can also set a limit for how many iterations your loop should run through. Each loop can run up to 500 times, but you can also set a lower limit if you’d like. 

Once you’ve added all the value sets that you want to loop through, and configured your other settings, click continue. Then, test your loop. 

In the test results, under “prevew_loop_values”, you’ll see the structure of your loop. 

Each iteration will include one instance of each value from your value sets. So in our example, each of our loop iterations includes a name, a task count, and a Slack ID, since those are the three value sets we created. 

Each iteration also includes an iteration number by default. 

The data that you see in the loop preview will be all of the data that your loop will retrieve and process as it runs, so make sure that you see the data you want to use in your loop before continuing. 

Once your step is all set up, it’s time to add actions to your loop.

Adding actions within your loop

Any action that you add after a loop step will be repeated once every time the loop iterates (unless the iteration stops at a filter first - we’ll cover filters in the next section). 

Every action before the loop will only run once, just like actions in any other Zap. In our example, the search step that we run after the trigger isn’t part of the loop, so it will only run once each time the automation runs. 

A rectangle starting at the loop step will give you an easy visual reminder of which actions are included in your loop. 

In our example, we’re going to use Slack to send a direct message to each person referenced in the loop. In the Slack message, we’ll include a personalized greeting for each user and a notice with the number of tasks that are currently assigned to them. 

When you’re using dynamic data from a loop, be careful about which variables you pick. The variables that start with “Preview Loop Values” will include data from several iterations. 

If you want to reference the data that belongs to a specific iteration, just use the variables that don’t start with “Preview Loop Values”. For instance, we’ve used the “Name” and “Task Count” variables in this Slack message. 

Testing a looped action

Once you’ve finished configuring your action, give it a test. 

When you test an action in a Zapier loop, it will only process test data for the first iteration in the loop. It’s not going to run test actions for every item. 

So even though our first step retrieved three records to loop through, testing the Slack step in the loop only sent one message, which is what we expected. 

Using a filter to add actions after your loop

Every action that you add after your loop step will be included in your loop. However, if you’d like certain actions to only run once after your loop, you can add a filter step. 

By configuring the filter so that only the final iteration passes, you can ensure that any actions added after the filter only run once, even though they’ll still technically be considered part of the loop. 

To add actions to your loop that only run once:

1. Add a "Filter by Zapier" action

2. Set the field to "Loop Iteration is Last", and set the condition to "(Boolean) Is True"

3. Add any actions that should run after the loop completes.

This setup ensures your post-loop actions only execute once, regardless of how many iterations your loop processes.

In our example, we’ll add another Slack action that sends a channel message. The message will include a list of everyone who received a direct message about their tasks. 

Running a live test of your loop

To see your full loop in action, publish the Zap and turn it on. 

Then, fulfill your Zap’s trigger condition. For our example, we just need to wait until the scheduled time in our trigger, which we’ve adjusted to occur in a few minutes. 

When your Zap runs, the loop will iterate for each item in your chosen data set. Every action in the loop will run once per iteration, except for any actions that you added after the filter. 

When our example automation runs, the Airtable search step retrieves three records in the “People” table. Each of the three people is sent a direct message. 

On the final iteration, the filter is cleared, and a single Slack channel message is sent summarizing the people who received messages. 

Alternative loop types: text loops and number loops

Text loops

A text loop is very similar to a line item loop. However, instead of iterating through several pieces of structured data, it will loop through pieces of text. 

For the loop to work correctly, your text will need to contain a “delimiter” between each item – like a comma, a semicolon, or even a space if you’d like (written as [:space:] )

It doesn’t matter what the delimiter is, as long as the delimiter is used consistently in the text. For instance, you can’t have some items separated by a comma and others separated by a semicolon. 

Each iteration of the loop will process a piece of text until it hits a delimiter. If you were to loop through the text “Apples, Pears, Bananas” using a comma as a delimiter, the loop will iterate three times: once for Apples, once for Pears, and once for Bananas. 

Number loops

When you create a loop from numbers, you won’t be iterating on data from previous steps in the Zap. Instead, you’ll be incrementing a number in a set pattern. 

You can set how many times the loop will run, as well as the loop interval number. So if you’d like, your loop iteration number can increase by 5 or 10 each time instead of just 1. 

For instance, in the loop pictured below, the iteration counter will start at zero and increase by 10 for every iteration until hitting the counter limit of 100. 

When it runs, the loop will just return its iteration number and repeat the steps you add to the loop. However, that iteration number is all the data the loop itself will process. 

Number loops are useful if you want to perform the exact same action multiple times in your Zap, or if you want to use the loop as part of a calculation. 

But you’ll probably be using a line item or text loop in most cases. 

Loops: Frequently Asked Questions

Q: Can you nest loops within loops?

A: No, Zapier doesn't support nested loops directly. Alternative solutions include:

• Using custom code steps

• Connecting separate Zaps using webhook triggers

• Refining your trigger to require only one dataset

Q: How does task usage work with loops?

A: The loop creation step doesn't consume a task. However, every action within the loop consumes tasks normally on every iteration. 

A: Can you use loops with paths?

Yes, but there are some limitations. You can only use one loop per Zap, so you can’t add loops to multiple paths in a single Zap. 

However, you can add paths to a loop as pictured below, which will still enable you to add quite a lot of conditional logic to your automations with loops. 

Efficiently processing datasets with loops

Loops are a convenient and efficient way to process structured data in your apps. 

With a single loop, you can easily run dynamic actions for hundreds of pieces of data in just one automation. 

If you’d like to learn more about automating your work with Zapier, be sure to check out the other posts on our blog or our YouTube channel. You can also follow XRay on Twitter, Facebook, or LinkedIn.

Similar Blog Posts

Not sure where to start with automation?

Hop on a 15-minute call with an XRay automation consultant to discuss your options and learn more about how we can help your team to get more done.

Schedule a 15-Minute Call