Error returned when marking invoice as paid

We are receiving errors when marking invoices as paid using your API.

Unfortunately the full response is not currently being logged and it is only occurring intermittently so it’s difficult to find the reason of the 422 response.

Can you tell me why we received a 422 response when creating a bank_transaction_explanation for invoice 6042 for app id bdEkNf0bU34BEqA006OeRw?

Hi James,

I’ve had a quick look through our logs, and it seems that the invoice which you’re unable to mark as paid is still in a draft state. It’s only possible to mark invoices which have been sent as paid within FreeAgent.

Hope that helps,
Paul.

Thanks Paul. That’s strange. The code for creating invoices hasn’t changed since the original development. We create an invoice, create a bank transaction and then send the invoice via email. This is working for the majority of invoices we are creating. However some invoices are being left in this draft state. What else could be causing these invoices to be marked as draft?

I honestly couldn’t say - some kind of race condition maybe? The correct order should be - create the invoice, mark it as sent (or send it by email), then create the payment.

I can’t see any requests hitting our servers for that invoice to send it, so possibly some kind of network blip causing the request to be lost?

Could you maybe add some logging of responses around those three requests to see what exceptions if any you’re seeing if it happens again?

Sorry I can’t throw any more light on this for you at the moment.

Kind Regards,
Paul.