Zapier automatically deduplicates incoming trigger data for your integration, so that Zaps do not run multiple times on the same data. Consider the following requirements for your “New Item” and “Updated Item” triggers to work as users expect.
id
is used as the primary key.primary
in outputFields
. See more information in the CLI docs.id
field. When a Zap is first turned on, Zapier makes an initial call to your API to retrieve existing data, and caches and stores each id
field in our database. When the Zap is turned off, that list is cleared.
Active Zaps then poll at an interval (based on a customer’s plan) and compare the id
s to all those seen before, trigger on new items, and update the list of seen id
s.
Now let’s say the user created a new task:
id
equal to 8
will be seen as a new item. That particular JSON object will then trigger the user’s Zap and complete any subsequent action steps the user has defined. The essence of deduplication is that the other id
s in the poll, 6
and 7
will be ignored, since their id
s have been seen in previous polls.
In order for deduplication to work, the id
field should always be supplied and unique amongst all items in the result.
Your API must return results in reverse-chronological order to make sure new/updated items can be found on the first page of results, as Zapier polling triggers don’t automatically fetch additional pages. If your API lists items in a different order by default, but allows for sorting, include an order or sorting field in your polling request to ensure newest records are returned on the first page of results. Github is a great example of an API that supports sorting on multiple fields in the asc
or desc
direction.
id
field or you’re adding an Updated Item trigger, you will use Code Mode to modify the API response.
id
wasn’t present. It is now required that you define one or more fields as the primary key.
By default, Zapier uses the field with the key id
as the primary key if no outputFields
has primary: true
. The id
field would be required in this case. Otherwise, your trigger would run into an error at runtime. If your API’s items have a differently-named unique field, adapt this code snippet to ensure this test passes:
id
field to be used for deduplication. Assuming your task API has an endpoint that can return tasks sorted by updatedAt
in descending direction, here’s example code to incorporate the updatedAt
value with the id
, so that Zapier recognizes a new update as a new item. Assuming that you have configured options
with the appropriate API request URL and parameters:
id
value before setting id
to a new combined value that is unique for every update of a task. This is useful to ensure that the original ID can still be used for other purposes, such as performing a search or associating records together.
Alternatively, if you’re using the CLI, you can set primary: true
for the id
and updatedAt
fields. See “How does deduplication work?” in the CLI docs for example code.