Ok. I see the idea behind it.
But here is the case that I think shows the problem in this idea. Imagine there is a restaurant chain. And let’s say they are opening two new locations. So they want to create two Square Locations as well. And now imagine they happen to do it at the same time. And their code to call the API endpoint is pretty straightforward: it calls the CreateLocation endpoint and puts the new location’s name in the payload. Now imagine the two new locations have the same name. So for both of these new locations, the endpoint call would have the same name. And given that these two calls happen within the same day, only the first call would create a new location. The second call would just receive the existing location in response. But the responses would be just identical. So both of the new restaurants would start using the same location on Square without even knowing it.
That’s the problem.
So the way I solve it now is I retrieve all the locations first, I check if there already is a location with the name equal to the one I’m about to create and if there already is one I change the name.
This way i have to always do an extra call to retrieve existing locations. While that would be much better for me to not do it and just be sure that if there already is one i will be notified about it in response.
Maybe I’m missing something… Is there a better way to handle the described situation?
PS this situation get’s much worse if you have no idea about this tricky responses behavior and don’t have a clue you have to handle it