I’m building an app using Zapier CLI and I’m stuck on how to handle multiple triggers from a single webhook. Our app sends all events to one URL. We can’t choose specific events to subscribe to.
Here’s what the webhook response looks like:
{
"event": "customer.signup",
"id": 42,
"other_data": "..."
}
I want each trigger to only fire for its matching event. For example, the ‘new order’ trigger should ignore ‘customer signup’ events.
What’s the best way to set this up in Zapier CLI? I’ve looked through the docs but couldn’t find anything about filtering events like this. Any tips or examples would be super helpful!
I’m pretty new to Zapier development, so sorry if this is a basic question. Thanks for any help!
hey, i’ve dealt with this before. you can handle multiple triggers by filtering events in your perform function. here’s a quick example:
const perform = (z, bundle) => {
if (bundle.cleanedRequest.event === bundle.inputData.eventType) {
return [bundle.cleanedRequest];
}
return [];
};
this lets you create separate triggers for different events using one webhook. hope this helps!
Having worked on similar projects, I can suggest a practical approach to handle multiple triggers from a single webhook in Zapier CLI. The key is to implement event filtering in your perform function.
In your perform function, you can add logic to check if the incoming event matches what the trigger is expecting. Here’s a basic example:
const perform = (z, bundle) => {
const incomingEvent = bundle.cleanedRequest.event;
const triggerEvent = bundle.inputData.eventType;
if (incomingEvent === triggerEvent) {
return [bundle.cleanedRequest];
}
return [];
};
This method allows you to create separate triggers for different events while still using a single webhook endpoint. It’s been a reliable solution in my projects and should work well for your use case too. Remember to properly set up your inputFields to allow users to specify which event type they’re interested in for each trigger.
As someone who’s worked extensively with Zapier CLI, I can share a solution that’s worked well for me in similar situations. The key is to implement event filtering in your webhook handler.
In your performSubscribe function, you can set up logic to filter events based on the trigger. Here’s a basic example:
const performSubscribe = (z, bundle) => {
const triggerEvent = bundle.inputData.eventType;
return z.request({
url: 'https://your-api.com/webhooks',
method: 'POST',
body: {
target_url: bundle.targetUrl,
event_type: triggerEvent
}
});
};
Then in your perform function, you can check if the incoming event matches what the trigger is looking for:
const perform = (z, bundle) => {
const incomingEvent = bundle.cleanedRequest.event;
const triggerEvent = bundle.inputData.eventType;
if (incomingEvent === triggerEvent) {
return [bundle.cleanedRequest];
}
return [];
};
This approach lets you create separate triggers for different events while still using a single webhook endpoint. It’s been a reliable solution in my projects.