My name is Dave and I am one of the Support Engineers here at FreeAgent.
Urgh, it sounds like you might have hit against a classic race condition.
POST request is received to the
v2/invoices end-point, we create a new in-memory invoice with a
reference that follows on from your last persisted invoice.
POST requests are received in rapid succession, we’ll (unfortunately) create two in-memory invoices, both with the same
reference, since neither invoice has yet been written to the database. The first invoice will be persisted successfully, whilst the second will fail since it no longer has a unique
It sounds like we need to take a closer look at how multiple
POST requests are handled at our end, to ensure there’s no crossing of the streams. I’ll raise this with our API team right away, though for now, you might want to consider adding a small
sleep statement in your loop to allow time for the first invoice to be created (and persisted), before the second request arrives. Sorry, I know that’s somewhat cludgy. Alternatively, you could explicitly pass the
reference attribute as part of your
POST request, so you could enforce uniqueness at your end.
I hope this helps and sorry for the confusion, Ben!