Add a round robin in your Zap

Routing leads has never been easier. Use only a single code step, instead of the usual three.

Add a round robin in your Zap

Have you ever found yourself overwhelmed while trying to add a round-robin to your Zapier workflow? In a previous post, I discussed a method that required three tasks per cycle.

But what if you could achieve the same result with just one task? That’s right, one task for the same outcome.

Ready to streamline your workflow?

Let’s dive in!

Ensuring Security

Before we jump into the setup, let’s address security. It's crucial to keep your stored information in Zapier secure. We'll generate a unique, nearly unguessable 'password' for the Storage by Zapier step using a UUID (version 4).

How to do it:

  • Generate a UUID: Visit a UUID generator to create a version 4 UUID. This string will act as your secure 'password' for your storage connection.

Using a UUID enhances security, ensuring your stored data remains protected.

Generate a version 4 UUID
  • Set Up Your Storage: Now, navigate to Zapier's Storage Connection page. Add a new connection and when prompted, paste in the UUID you generated and confirm.

Paste v4 UUID
Paste v4 UUID

Step-by-Step Guide:

  1. Add Code by Zapier: In your existing Zap, add a new step and choose 'Code by Zapier'. Then, pick the 'Run Python' action.

  2. Fill in Input Data:

    • Name the first row 'array' and map or select a list for its input.

    • Name the second row 'secret' and paste the UUID you generated earlier into this row.

  3. Input the Code: Paste the provided Python code for the round-robin in the 'Code' field.

By following these steps, you’re not only adding a round-robin to your Zap, but you’re doing it securely and efficiently!

round-robin Python code
Round Robin Code setup

Here’s the code to copy/paste:

1import requests
2
3# Function to interact with StoreClient
4def store_client(secret, key, action=None, value=None):
5 headers = {"X-Secret": secret}
6 base_url = "https://store.zapier.com/api/records"
7
8 if action: # PATCH request
9 payload = {"action": action, "data": {"key": key}}
10 if value is not None:
11 payload["data"].update(value)
12 response = requests.patch(base_url, headers=headers, json=payload)
13 response.raise_for_status()
14 return response.json()
15
16 else: # GET request
17 response = requests.get(f"{base_url}/{key}", headers=headers)
18 if response.status_code == 404: # Key not found
19 return None
20 response.raise_for_status()
21 return response.json().get("value")
22
23# Get the array and secret from inputData
24array = inputData.get('array', '').split(',')
25secret = inputData.get('secret', '')
26
27# Fetch and increment the current index
28current_index = store_client(secret, "currentIndex", action="increment_by", value={"amount": 1})
29if current_index is None: # If index does not exist, initialize and use 0
30 current_index = 0
31 store_client(secret, "currentIndex", action="set_value_if", value={"value": 0})
32
33# Calculate the next index based on the incremented value
34next_index = current_index % len(array)
35
36# Prepare the output
37output = {
38 'result': array[next_index],
39 'current_index': next_index
40}
41
42return output

Time to Test:

Hit 'Test' to run this new Code by Zapier action. If all goes well, you'll successfully cycle through your list of values using just one task.

When Going Live:

Once satisfied with the test, publish your Zap. The beauty of this setup is your round-robin will resume from where it left last, ensuring smooth operation.

Congratulations! You've just simplified your Zapier workflow by adding a secure, efficient round-robin—in just one task! Impressive, isn’t it? If you have any questions or face any hurdles, feel free to drop a comment below. I’m here to help!

Wishing you a productive day ahead!

Comments