I've found that Http 207 can be used for bulk insert/delete/... etc. operations where we potentially have multiple items being inserted and partial success is ok from business perspective.
I wonder if the same thing applies if we have API Post calling some external services?
Example business scenario:
We have HttpPost endpoint that is creating an order.
HttpPost:
/api/order/
Now let's assume that this endpoint besides creation of an Order would be calling external service to also print a label for that order and another one to send some kind of confirmation via REST to external 3rd party system.
Now in this scenario we assume that creation of Order is a must for the success of this operation but both printing and external REST call can return error message. Potentially that is besides our control.
Now from what I've read the options on how to return this information would be:
- Http 200 with some kind of object containing necessary information. For example:
{ "isSucess": true, "isFailure": true, "erorMesage": "string" }
- Make the endpoint more RESTful and separate it into 3 actions which would be called, but in this case this is not applicable (at least from my perspective) because all of those things are tightly coupled from business perspective and they should be bound together
- Return 5xx error. 502 since not all of the actions succeeded and there were some internal problems, but what if one failed action is 502 and another 503
- Return 207 error with proper error response for each of the actions (Order creation: 200, Printing: 502, External 3rd party: 502)
Now I wonder which would be most suitable ? I'm kind of leaning towards 502 error or 207 since they in my opinion provide the most information about the actual state of the system.