Forum Discussion

tadev's avatar
2 days ago

Issue with MYOB Business API: 409 Conflict when sending multiple POST requests

This is not a support request, it is more like an issue I recently encountered, and since I could not find any documentation about it in the API docs, I thought I'd post it here to save other developers time in the future.

Undocumented limitation with MYOB Business API: 409 Conflict on sending multiple POST requests in parallel

Issue Summary

While integrating with the MYOB AccountRight API, I encountered an issue when creating new Bills via the API. When submitting multiple POST requests in quick succession, some of them intermittently fail with a 409 Conflict error. The error message returned is:

"An Update operation requires the latest RowVersion for each of the existing entities being modified."

This is unexpected behavior since this error message is typically associated with PUT requests (updates), not POST requests (new record creation).

Expected vs. Actual Behavior

  • Expected Behavior: Each POST request should successfully create a new Bill, returning the newly created Bill’s details.
  • Actual Behavior: Some POST requests fail with a 409 Conflict error, while others succeed. Resubmitting the same failed request later often results in a successful response, without any changes to the request payload.

Steps to Reproduce

  1. Send multiple POST requests to create Bills in rapid succession (e.g., five requests in parallel).
  2. Observe that some requests fail with a 409 Conflict error while others succeed.
  3. Resubmit the failed request later - it may succeed without any modifications.

Analysis

The error message suggests that MYOB is incorrectly treating some POST requests as PUT requests, possibly due to an internal concurrency issue. This behavior is undocumented, and no clear explanation is provided in the API documentation.

Possible causes include:

  • Concurrency limitations within the MYOB API when processing multiple requests simultaneously.
  • Internal caching or sync delays causing some transactions to be misclassified as updates.
  • Thread safety issues where parallel requests interfere with each other.

MYOB API Support Response

After raising this issue with MYOB API support, it was confirmed that the API does not handle multiple simultaneous POST requests to the same database correctly. Their recommendation was to add a delay between each request to ensure successful processing.

"We have had requests to open this up, but we would need some significant updates to be able to do so. Going forward, you will need to provide space between each call."

Workaround

To avoid encountering this issue, implement the following workaround:

  • Send requests sequentially, ensuring each request completes before sending the next.
  • Introduce a delay of a few seconds between consecutive POST requests.
  • Implement automatic retries with exponential backoff when encountering a 409 Conflict error.

For example, in a microservices-based architecture, detecting this specific error and retrying after a short delay can help mitigate the issue.

Conclusion

This undocumented limitation can cause unexpected failures when batch submitting Bills via the MYOB API. Until MYOB updates their API to handle parallel requests correctly, developers should implement sequential request processing or introduce delays to ensure reliability.

Hopefully, this post saves others time troubleshooting similar issues!

No RepliesBe the first to reply