Skip to main content

In my integration I’ve put a Find event, and a Create event, and linked them together to support Find-Or-Create.  But I’m struggling to see how to make that useful in practice, because of how it uses the same parameter data for both the Find and the Create.  I’m finding that I always want to use different parameters for the Find and Create.  Perhaps this is because the structure or behavior of my API is not as it ought to be.  I’d love to hear if any other devs have thoughts on this.

 

Simplified example:

My APIs are working with records that have a Reference and a Name.  The Reference is an immutable unique key, and the Name is a mutable data field.  However, the Name is mandatory - I can’t create a record without one, and my Create API will return an error if this is attempted.

A typical use case would be to have a Zap that pulls these records from some other system, matching against my API by Reference, and telling my API to create or update the Name as appropriate.

If the Zap does a Find based on Reference, then the Create part of the Find-Or-Create will fail because the mandatory Name field is not supplied.

If the Zap does a Find with both the Reference and the Name, then it fails to find a match if the Name has changed, and tries to create a new record with a duplicate Reference.

 

What should I be doing here?  I can think of a few options but they all seem to have shortcomings.

I could write my Find API to accept the non-key fields, but ignore them - i.e. accept both Reference and Name, but search only by Reference.  But then I’m precluding anyone being able to search by Name if they want to do that in another situation.

I could change the Create API so that all non-key fields are non-mandatory, and you can Create a record with just a Reference - but then I have data validity issues.  I can hope that the writer of a Zap will add an Update action afterwards to fill in the Name, but they might not.

How do integration writers generally go about making Find-Or-Create usable?

Hey @Tytila 👋

Find or Create actions are generally used to find a record by a mutable field - say by name or email. To give you an idea of the record types commonly used, check out the Search or Creates examples here: https://platform.zapier.com/quickstart/must-have-triggers-and-actions - searching by email would be recommended as that would be a truly unique value, whereas presumably some records could have the same names. 

From your description (and depending on your API’s capabilities), I’d expect to have the Find action search by name; and if not found, create a new record with that name - where the new Reference value is created. If Reference is the unique id for a record in your platform, then searching by that would not be useful as a separate triggering app (in a user’s Zap) would never be able to provide the unique id your API expects.

If the goal is to add the name to the existing record, then an Update Record step would be needed after the Find Record step - Zapier users are usually quite familiar with that as a concept, if the use case is to add fields to existing records. An example in our help docs (for end users) describes the Zap setup: https://help.zapier.com/hc/en-us/articles/8496241402253-Search-for-existing-data-in-Zaps#3-add-your-search-criteria-0-2 


Hi Marina, thanks for taking the time to reply.

The kind of scenario I’m thinking about is using Zapier to synchronize data between two systems, that maybe hold duplicate data, or if not exactly duplicated, at least contain some records with a 1:1 correspondence.  So when a record is touched on system A, a Zap would replicate that change to system B; updating an existing record on system B if there is one, or creating a new one if not.

Clearly the two systems need some sort of shared key that the Zap can search for in system B.  I don’t really get how you would manage using a mutable field for that purpose.  For example, say we use the email address.  What if I change a person’s email address on system A? The Zap looks for that email address in system B, doesn’t find it, so creates a new record with that email address on system B: now I have two records for the same person on system B, one with their old email address and one with their new one.

Is Find-Or-Create not appropriate for this synchronization/replication type of scenario?  It seems like it would be really useful to have a simple way to say “update this record if it exists, or create it if it doesn’t”, where existence is determined based on a key value that is not part of the mutable record data.

Currently our workaround is to have two separate Zaps.  Both search the target system for a matching record based on a key; one has a condition to continue if no match is found, and does a create; the other continues if there is a match, and does an update.  I feel that’s not very intuitive for the Zap designer, and it involves a lot of duplication between the Zaps.


Hi @Tytila

Thanks for those details! This sounds like a classic 2 way sync use case - which is not Zapier’s primary use case: https://help.zapier.com/hc/en-us/articles/8495908569613-Does-Zapier-support-two-way-syncing 

Using two Zaps with filters for this purpose is going to be the best method for what you describe.  `Find or Create` actions serve a different purpose as I described and is illustrated for example apps here:  https://platform.zapier.com/quickstart/must-have-triggers-and-actions 

For your use case, there will need to be a unique id that is the source of truth between the two platforms you are syncing, and you’ll want to make sure to consider the risk of Zap loops: https://help.zapier.com/hc/en-us/articles/8496232045453-Zap-is-stuck-in-a-loop 


Reply