Zapier Loop Action

With the amount of data being collected and the number of tasks to be completed for this data increasing, the ability to iterate and perform actions for each row in a dataset is vitally important for the marketing operations lead. This post will show you how to use a Zapier loop action to loop through and update rows of a Google sheet to give you a solid foundation that you can then build upon in your own Zaps.

On a related note are you interested in learning more about APIs? APIs are the foundational building blocks that power modern software ecosystems like Zapier and the Demystify the API Crash Course will explain the fundamentals and give you a hands-on introduction to making your first API requests. Check out the course using the button below 🙂

Take Tyron’s Course on Demand

Explore the Demystify the API Crash Course

Introduction

For this post, we will use an example customer database in Google Sheets containing the “First Name”, “Order #”, “Email Address”, “Phone Number”, and “Delivery Date” of each customer. The “Delivery Today?” field is a checkbox field, which indicates whether the customer’s order will be delivered today.

We will use a Zapier loop action to compare today’s date to the “Delivery Date” value for every customer to set this “Delivery Today?” field to either be TRUE or FALSE. As shown in the second image below, we will use the “Schedule by Zapier” app to trigger this zap to run every day so that the “Delivery Today?” column is always up to date.

A Google sheet containing rows of customer information
Database of customer information
The "Schedule by Zapier" trigger being used to run the Zapier loop action every day
Trigger to run the Zapier loop action every day

Zapier Loop Action Workflow

An overview of the actions contained within the Zapier loop action
Zapier loop action overview

Zapier Loop Action Setup

The “Create loop from numbers” action event from the “Looping by Zapier” app is used to loop through each of the rows in the customer database. Since the first row of the Google Sheet is the header and we want to loop through every row, we will set the “Loop Iteration Counter Start” to 2 and the “Loop Iteration Counter Increment Amount” to 1.

With these 2 parameters set and taking into account Zapier’s 500 loop iterations restriction that means the maximum value we can set the “Loop Iteration Counter End” to is 501. If you have more than 500 rows of data that you need to update then you will need to use nested looping in Zapier (see the Zapier For Each Loop Quick-Start Guide).

Zapier loop action configuration
Zapier loop action configuration

Get Google Sheet Row

Once the Zap has been triggered, the first step is to obtain the “Delivery Date” value for the customer in a row. To do this the “Get Many Spreadsheet Rows” action from the Google Sheets app is used to pull in 1 row at a time from columns A to F. The “Loop Iteration” value from the Zapier loop action is used in the “First Row” field so that each row of the sheet will successively be accessed with each iteration of the loop.

If you want to see how to use the “Get Many Spreadsheet Rows” action to pull in multiple rows at once and how to transform the output to be used in subsequent actions then take a look at the How to use Zapier with Google Sheets post. Alternatively, take a peek at the Zapier Google Sheets Quick-Start Guide for more general guidance on the best option to import data from Google Sheets depending on the number of rows or the amount of data you want to import.

Setup of the Zapier "Get Many Spreadsheet Rows" action
Get row from Google Sheet

Python Code

Next, we will use a few lines of Python code to determine whether today’s date matches the “Delivery Date” for this customer. Since the “Delivery Date” column in the Google Sheet is in dd/mm/yyyy format, the “Date Month, “Date Day”, and “Date Year” output from the “Schedule by Zapier” trigger are joined together using the “/” character so that we can get today’s date in the same format.

The Python code then splits the string output from the “Get Many Spreadsheet Rows” action into an array using the “,” character as a delimiter and accesses the 5th column of this array to get the customer’s “Delivery Date” value (P.S. array indexing starts at 0 in Python which is why we use array[4] instead of array[5] below).

Then a conditional logic statement is used to set the delivered_today variable to TRUE or FALSE depending on whether today’s date equals the “Delivery Date” value for this customer.

array = input['row'].split(",")

if array[4] == input['today']:
    delivered_today = True 
else:
    delivered_today = False

return {'delivered_today':delivered_today}
Python code in the "Code by Zapier" action to check if the delivery date is today
Python code to check if delivery date is today

Update Google Sheet Row

The final step involves using the “Update Spreadsheet Row in Google Sheets” action to set the “Delivery Today?” field equal to the “Delivered Today” output from the Python code in Step 4. Notice again how the “Loop Iteration” output from the Zapier loop action is used to specify which row in the Google Sheet should be updated.

Part 1 of the setup for the "Update Spreadsheet Row" action in Zapier
Part 2 of the setup for the "Update Spreadsheet Row" action in Zapier
Update row from Google Sheet

What’s Next?

Now that you have gotten a taste of looping in Zapier there might be a few more things that you are interested in doing now:

About The Author — Tyron Pretorius
Tyron Pretorius

Greetings fellow MO Pros! As a previous mechanical engineer turned marketing operations lead, I now fancy myself as a full-stack marketer capable of designing websites, writing SEO-optimized content, and doing all the tracking and automation on the backend. That being said my bread and butter is marketing operations and I love to get down and dirty with the Marketo API, Python, Zapier, and Google Scripts.

Related free workshops

The New Four Pillars of Marketing Operations

The New Four Pillars of Marketing Operations

Created with the assistance of DALL·E Introduction and Background In 2018, Edward Unthank introduced the four pillars of marketing operations, setting the stage for the management of effective marketing technology (Martech) functions. These pillars have since been the bedrock for many successful careers in marketing operations. My journey to redefine

Become a member
The Role of Front-End Martech Tools in the Age of Generative AI

The Role of Front-End Martech Tools in the Age of Generative AI

Introduction: Blending Human and Technical Perspectives in Martech Caption: Future gardens of martech will blend human and AI perspectives As a co-host of the Humans of Martech podcast, I’ve had the privilege of interviewing some of the brightest minds in marketing technology. This unique experience has provided a blend of

Become a member