We’re developing a connector for our application and we want it to trigger when a value crosses a threshold. Our API just returns the current value as a number (and there’s not a way to call the API to ask “what was this value 5 minutes ago?”). If the zap could remember the previous value it saw, then our connector’s code could check
if (previousValue < threshold && currentValue >= threshold) and only trigger the one time it crosses the threshold.
Is this possible?
What we’re currently doing is essentially this:
id: value >= threshold ? "above" : "below"
Zapier thinks it’s a new object when the ID changes, but once Zapier has seen both IDs (“above” and “below”) then it stops triggering. We can append the current date to the ID so it triggers once a day at least, but ideally we’d like to only trigger on transitions (i.e. crossing above or below the threshold).
Best answer by xavdidView original
For the best user experience my first suggestion would be executing this logic in the app, and surfacing the event as a subscription webhook, rather than trying to manage state within your Zapier integration. Sounds like you’ve identified a valuable use case for your users - “notify me when a value changes beyond X amount”. Hook events are ideal for this kind of use case and make it easy for the user to consume it.
I certainly understand why that’s your first suggestion but I’d also like to know what your second suggestion is
I’d prefer to get things working without having to change our services or API. I’m ok with the latency of a polling-based trigger, if we can get it working that way, since it’d let us build out our connector more easily.
z.cursorsounds like it’s used to store some information between calls for pagination purposes. Can that be repurposed to store other values between runs?
A couple of notes:
@xavdid thanks! I was able to get it working!!
Two other things to note:
awaitbefore the get() and set() calls. It was obvious I should’ve needed that on the get call, but skipping it for the set() made the zap complete but not show the error caused by passing in a number.