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?