0

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(),
  },
};
Deepak
  • 1
  • 1

1 Answers1

1

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 at updated_at at all and is working as intended (new items only). From those docs:

Zapier needs a composite id field that changes whenever the item is updated

So your second approach is correct. The id field should be a combination of the original id and the updated_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 .filter before your .map, but will need a way to identify new (not updated) objects. Shot in the dark, but if time is the created date and modTime is the updated date, you could filter to only return objects where time !== modTime. But, this may not be the case.

Ultimately, whatever you reeturn from listData will get send to the deduper and triggered on if that zap hasn't seen that id before.

Hope that clears it up!

xavdid
  • 5,092
  • 3
  • 20
  • 32