I am trying to create a trigger (Poll based) in Zapier app/integration which should run the zap when an existing item will be updated.
API response contains an array like this:
[
{ id: 1, title: 'AWS', time: '2021-12-03T11:41:13.615Z', modTime: '2021-12-03T11:41:13.615Z' },
{ id: 2, title: 'GCP', time: '2021-12-03T11:41:13.615Z', modTime: '2021-12-03T11:46:13.615Z' },
]
Now, as per the doc, if an item will contain id and updated_at key then it should work if same record will be updated with last modified timestamp field.
To make an update trigger, use an API endpoint that lists all items, both new and updated, or alternately an endpoint that lists only updated items. Zapier needs a composite id field that changes whenever the item is updated (ideally z.hash('md5', item.id + item.updated_at)), so subsequent updates aren’t be filtered out by Zapier’s deduper.
For that, I created a new key updated_at and copied the value of modTime key. But this trigger is working only for new records and not for any update in existing record. Am I missing something ? I can make id every time new like this { id: rec.id + ':' + rec.modTime ... } but it will run for new records as well which I don't want.
Here is my code:
// import statements
const listData = async (z) => {
const records = await getTaskList(z);
return records.map((rec) => ({
...rec,
updated_at: rec.modTime
}));
};
export default {
display: {
description: 'Triggers when a task will be updated.',
label: 'Task Updated',
},
key: 'task_updated',
noun: 'Updated Task',
operation: {
outputFields: outFields,
perform: listData,
sample: getSampleData(),
},
};
Great question! The Zapier deduper only cares about the field named
id. That's why your solution of only adding a key only works for new items- the deuper doesn't look atupdated_atat all and is working as intended (new items only). From those docs:So your second approach is correct. The
idfield should be a combination of the originalidand theupdated_field. This will trigger for all new and updated objects.Filtering out new objects depends on the API you're sourcing data from. You can do a
.filterbefore your.map, but will need a way to identify new (not updated) objects. Shot in the dark, but iftimeis the created date andmodTimeis the updated date, you could filter to only return objects wheretime !== modTime. But, this may not be the case.Ultimately, whatever you reeturn from
listDatawill get send to the deduper and triggered on if that zap hasn't seen thatidbefore.Hope that clears it up!