Best answer

Handle loops and non-loops in same Zap flow?


Hello!

 

Bit of backstory.  We ran into an issue with Salesforce and Zapier where we had an outbound message starting a Zap that ends up sending a slack message.  However when Salesforce send multiple sets of data in the same outbound message (for instance via a batch update in Salesforce), the Zap would break because it couldn’t split up the data.

 

I found a way to get it to work using the Loops functionality, but now that new “looping Zap” won’t work for single messages caught in the webhook, and the original “single Zap” still can’t handle multiple messages.  So we would have to have two zaps running that would fail in the opposite scenario.

 

Is there a way to build both of these into the same Zap and have it run one way (with loops) if there is multiple sets of data and then another way (without loops) if there isn’t?  The Filter option only has the ability to stop or go forward from what I can tell, not branch, and even then I didn’t see any option to differentiate based on the incoming webhook.  This seems to be the only option as the “Loop” action is what breaks if there is only one.

 

Any guidance would be appreciated!

icon

Best answer by ForYourIT 2 October 2021, 18:33

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

10 replies

Userlevel 7
Badge +14

Hi @Divvynaut 

Try Paths: https://zapier.com/apps/paths/integrations

 

FYI: Looping can work for 1+ loops.

Looping: https://zapier.com/apps/looping/integrations

 

Perhaps you can outline the 2 different examples and how your have your Zap steps configured for us in order to better evaluate, thanks.

Hi @Divvynaut 

Try Paths: https://zapier.com/apps/paths/integrations

 

 

This is helpful thank you!

 

I’m still a little stuck on how I can differentiate if it needs to be looped or not based on the data coming in on the webhook action.  I don’t see which Zapier webhook “field” in the data is usable to tell.  I’ll keep messing with specifics in the data maybe in the meantime.

 

 

Userlevel 7
Badge +14

@Divvynaut 

Perhaps you can outline the 2 different examples and how your have your Zap steps configured for us in order to better evaluate, thanks.

FYI: Looping can work for 1+ loops.

Hey @Troy Tessalone ,

 

Sorry that’s what I was trying to do above, ha.

So I’m just trying to go off of the webhook right now
 

Step 1:  Catch the hook and get the data (Success!)
 

 

Step 2:  How to conditionally run based on the webhook data having multiple sets of data (Not sure?)

Webhook Envelope Body - 

Webhook Notifications - 
 


Again I’m not sure how to tell based on the options I am given by what Zapier grabs in the Webhook Action.  I don’t see a filter for “Number of Notifications” for example.  It seems like we can only go off of the data that is actually grabbed by the hook.
 


  That’s where I’m stuck currently.

Userlevel 7
Badge +14

@Divvynaut 

It’s still unclear what data points from the Zap trigger step that you are trying to map to the Looping action step.

Please post screenshots.

Can you list examples where there is a SINGLE vs MULTIPLE values?

 

I’m not trying to map to the looping section.  I’m trying to filter based on incoming data for the paths.

This is before it even gets to the looping stage (which I have working fine, no questions there)

 

To reiterate the use case:

I have data coming into the webhook.  It could be 1 “set” of data, or it could be multiple “sets” of data.  Based on just the webhook action and data it grabs, can we branch into different Paths based only on that action/data having 1 or multiple sets?

 

 

Userlevel 7
Badge +14

@Divvynaut 

If you can post screenshots of how your have the Looping step configured, then we may be able to help advise about how to configure the Filter step.

And...

Can you list examples where there is a SINGLE vs MULTIPLE values?

@Troy Tessalone I’m trying to filter off the webhook data BEFORE the loop.  Are you saying I have to loop first?  The data looks exactly the same in either scenario, it either has numbered notifications (as I posted above) or just one, non-numbered notification 

“No-numbered” Notification:

 

Userlevel 7
Badge +14

@Divvynaut 

I’m looking for these screenshots from your side to help troubleshoot:

  1. Screenshot(s) indicating a SINGLE output from the Zap trigger with the data points mapped to the Looping action step
  2. Screenshot(s) indicating a MULTIPLE output from the Zap trigger with the data points mapped to the Looping action step

Based on those examples we may be able to determine the differences in the data structures of SINGLE vs MULTIPLE, which may be able to help determine the proper way to configure the Filters.

Userlevel 7
Badge +7

Hi @Divvynaut,

So from what I understand you would like to check the amount of items in your notifications from the webhook, and then act upon this afterwards. Lets say for example more than 2 this, only 1 that.

I currently don’t know of a simpler way to do this, but you most likely will have to use code for this.
Since Zapier doesn’t give you all the webhook data, you need to catch a raw webhook and then parse this using some code:

  • Step 1: Catch raw hook (this will catch the webhook, but not parse it so you can use it later)
  • Step 2: Code by Zapier, run Javascript (Here we check the data from the webhook, parse it and check the length of the array)
  • Step 3: Paths by zapier (have a condition which checks the length we got, and based upon this do something)

I am not completely sure how the data looks (which you get from the webhook) since your screenshots are limited, but the code will look something like this:

var json = inputData.body;
var obj = JSON.parse(json);
var length = obj.notifications.length;

//console.log(obj.notifications);

output = [{length: length}];

Important: In the code step, you need to add a variable called “body” which contains the value of the raw body from the webhook. (see screenshots).

 

Then in the last step you can use a condition which checks the length variable from earlier:

  • If its less than 2 (AKA 1) then do this
  • If its more than 1 (AKA 2 and more) do that

 

Let me know if this works or not. Hope this helps!

~Bjorn

 

Screenshots: