How does the 'Code by Zapier' trigger function independently?

I’m trying to figure out how to use the ‘Code by Zapier’ feature as a trigger in my zaps. I understand how it works as an action, but I’m confused about its behavior when used as a trigger.

When I set it up as a trigger, I can’t tell what makes the zap start on its own. Normally, other triggers activate when a webhook is sent to Zapier, but there’s no webhook involved with ‘Code by Zapier.’

What is the mechanism behind this? How does Zapier decide when to run the zap without any obvious external input? I’ve set it up, yet I’m still unsure about the actual event that triggers it.

Here’s a simple example to illustrate my question:

function runTrigger() {
  const info = {
    event: 'action_detected',
    time: Date.now()
  };
  return [info];
}

Can someone explain how this trigger operates? I’m really curious about how this feature works behind the scenes.

The ‘Code by Zapier’ trigger operates on a polling mechanism. It executes your custom code at regular intervals, typically every 5-10 minutes depending on your Zapier plan. This means Zapier runs your code periodically to check for new data or conditions you’ve specified.

Your code must return an array of objects. If this array contains items, it triggers the subsequent steps in your Zap. If it’s empty, nothing happens. This allows you to create custom logic for when your Zap should fire.

Keep in mind that there are execution time limits - 1 second for free accounts, up to 10 seconds for paid plans. It’s crucial to optimize your code to run within these constraints.

This polling approach enables you to create triggers based on complex conditions or data from external sources without relying on webhooks.

Having used ‘Code by Zapier’ as a trigger myself, I can shed some light on how it operates. It’s essentially a scheduled task that Zapier runs periodically - usually every 5-10 minutes depending on your plan. Your code doesn’t actually ‘trigger’ in real-time. Instead, Zapier executes it on a set schedule. If your code returns any data (like in your example), Zapier treats that as a new trigger event and proceeds with the next steps in your Zap. One gotcha I’ve encountered is the execution time limit. Make sure your code runs quickly, especially if you’re on a free plan with stricter limits. I’ve had to optimize my triggers a few times to avoid timeouts. Also, remember that this approach isn’t instant. If you need real-time triggers, you might want to look into webhook-based solutions instead. But for many use cases, this polling approach works well enough.

hey there! so ‘code by zapier’ as a trigger is basically zapier running ur code every few mins. it’s not instant like webhooks. ur code needs to return an array - if it’s not empty, zapier takes that as a trigger event. just watch out for time limits, especially on free plans. it’s great for custom checks but if u need real-time stuff, maybe look at other options.