New invoice creation API error

Using code that has been in production for maybe nearly a decade, which has obviously been tweaked here and there as the FreeAgent API has been adjusted, I am now getting an error when I try to create an invoice. The error is as follows:

Client error: POST https://api.freeagent.com/v2/invoices resulted in a 422 Unprocessable Entity response: {"errors":[{"message":"contact_id can't be blank"}]}

Here is the body of the data that I am sending to the invoices endpoint (I’ve obviously redacted certain items).

array ( 'contact' => 'https://api.freeagent.com/v2/contacts/123456', 'dated_on' => '2026-07-01', 'payment_terms_in_days' => 9, 'currency' => 'EUR', 'invoice_items' => array ( 0 => array ( 'item_type' => 'Months', 'description' => 'Software Subscription', 'quantity' => 1, 'price' => 18.2, 'sales_tax_rate' => 0.0, 'category' => 'https://api.freeagent.com/v2/categories/002', ), ), 'ec_status' => 'Reverse Charge', )

Could someone please help explain why we’re suddenly looking for contact_id and why this is failing suddenly?

I’ve tried including contact_id as well as in place of contact. I can’t seem to get anything to work.

there was a guzzle library change that broke my implementation. You can delete/ignore this.

1 Like

Hey ptgnet - good timing, I was just taking a look! Thanks for updating us, much appreciated :slight_smile:

Alex D, FreeAgent

Just to let you know what the problem was. The issue was that the change in the guzzle library and the way I was using it meant that the payload was NOT sent within an invoice key. It might be worth looking at why the API is returning an error about contact_id when that wasn’t the problem. If the API had said there was no invoice data in the payload, it might have pointed me more quickly to the problem, but contact_id was a red herring that sent me off in a completely different direction.