3

I want to create a zap with branching logic. I want to do this since the gateway/REST API am using supports addition of only one web hook. I require a Zap that can perform Action 'A' when suppose trigger returns an event with 'event_type' = 'alpha' and Action 'B' will be performed when the same trigger returns an event with 'event_type' = 'beta'

example:

if trigger_A.output.event_type = 'alpha'
       then 'Send mail' to 'abc@xyz.com'
else if trigger_A.output.event_type = 'beta'
       then 'Send message' to 'Slack'
else
       post in 'Facebook' trigger_A.output.message

Is this possible with a single Zap?

NOTE that I cannot add multiple webhooks to my REST API, and hence I cannot have multiple Triggers, and I can use use maximum 1 Zap.

Any help from the forum would be appreciated.

Sam
  • 139
  • 13

2 Answers2

6

edit: This answer is outdated. See the other answer about Zapier's first-party support for Paths.


David here, from the Zapier Platform team.

I've got good news and bad news! The bad: this is not currently possible out of the box. It's being discussed internally and we have nothing further to say about it at this time.

The good news is that the workflow you describe is possible, but it'll take a few zaps:

Zap A: Webhooks (catch) -> Code -> Webhooks (post)
Zap B: Webhooks (catch) -> Gmail (send mail)
Zap C: Webhooks (catch) -> Slack (send message)
Zap D: Webhooks (catch) -> Facebook (create new post)

The steps are as follows:

  1. Your service sends a webhook to Zap A with a key+value describing event_type
  2. You have a code step that runs the real version of the pseudocode you posted above, setting a url variable based on the event type. Zaps B,C,D each have a unique url for their trigger, all of which are known to Zap A.
  3. Zap A posts to the url returned in step 2, sending along whatever data you'd like.
  4. One of the child zaps (B,C,D) gets triggered, doing the desired action.

So there you have it! Not pretty, but certainly doable.

​Let me know if you've got any other questions!

xavdid
  • 5,092
  • 3
  • 20
  • 32
  • Thanks David. It will be a great help to me. Wondering if I can code (using Zapier CLI) triggers with static hooks and implement the logic of filtration inside the trigger, and you Zap A just to forward data (using Zapier webhook action POST) to triggers of Zap B, Zap C, Zap D. – Sam Sep 20 '17 at 11:46
  • Yep, that would work too! I would stick with the built-in webhooks app for the trigger, but you could make a custom CLI app that has an action `Route Hook`, which contains all of your routing and other zap logic. Unfortunately, you can't manually make a trigger with a static hook that you specify. You can use REST hook triggers, but the url will change each time the zap is turned on or off (I believe). So not super easy. – xavdid Sep 21 '17 at 00:23
5

I know this is an old question, but it's worth sharing the good news. You can now define branching logic with Zapier out-of-the-box:

Paths let you build advanced workflows to run different actions based on conditions you decide. Paths are Zapier's conditional logic tool. Think of Paths as If/then logic: if A happens in your trigger app, then do this, if B happens then do something else, and so on.

The Paths feature is only available on Professional, Professional Plus, and Teams plan accounts. More can be found in the Zapier documentation on Paths.

Another option that may be helpful is using filters and multiple zaps.

Jeroen Heier
  • 3,520
  • 15
  • 31
  • 32
niyi
  • 319
  • 2
  • 3
  • it's not if/else logic though, it's if/if logic. There isn't any way to run them exclusively, unfortunately, which is the whole concept of a branch! – Code Wiget Jan 08 '21 at 18:38
  • True but if else is really complex if ifs if you think about it. For example, with the OP's workflow, you have: Branch B: if trigger_A.output.event_type = 'beta' Branch C: if trigger_A.output.event_type != 'beta' and if trigger_A.output.event_type != 'beta' – niyi Jan 29 '21 at 15:20