Contact can't be blank whilst it's filled with url

Hello FreeAgent team.
Could you please tell me what value of ‘contact’ should be sent when passing a new invoice?
I am getting “422: Unprocessable Entity contact can’t be blank” whilst my contact is filled with URL.
It’s sandbox, app id 6031.
Best regards!

Hello,

It looks as though the contact in your requests may not be inside the invoice block, e.g.

{
  "invoice": {
    "contact": "https://api.freeagent.com/v2/contacts/12345",
    "dated_on": "2023-01-03"
    ...
  }
}

Instead, it’s at the top level alongside invoice rather than inside it. invoice_items and other parameters also need to be nested inside invoice.

There’s a more complete example here: Create an invoice.

If you’re still getting issues, could you provide a copy of the request body please?

Kind regards,
Dominic

Hello Dominic, thank you for the express answer.
Yeah - trying using the invoice wrapper and without.
When wrapping it, the error is different and it’s " 400: Bad Request Invalid nominal code test".

My example payload:

{
  "invoice": {
    "status": "Draft",
    "long_status": "Open – due in 1 day",
    "contact": "https://api.sandbox.freeagent.com/v2/contacts/110386",
    "include_timeslips": null,
    "include_expenses": null,
    "include_estimates": null,
    "reference": null,
    "dated_on": "2022-12-29",
    "due_on": "2023-01-01",
    "payment_terms_in_days": 0,
    "currency": "PLN",
    "cis_rate": null,
    "cis_deduction_rate": 0,
    "cis_deduction": 0,
    "cis_deduction_suffered": 0,
    "comments": "Account number: <u></u>\r\n123456789123456791\r\n\r\nSomething blahblah",
    "invoice_items": [
      {
        "description": "Beloved&nbsp;X 456",
        "position": 1,
        "item_type": "Products",
        "quantity": "1",
        "price": "54.9900",
        "sales_tax_rate": 18,
        "second_sales_tax_rate": 19,
        "sales_tax_status": "TAXABLE",
        "second_sales_tax_status": "TAXABLE",
        "category": "test"
      },
      {
        "description": "Delivery: ",
        "position": 2,
        "item_type": "Products",
        "quantity": "1",
        "price": "0.0000",
        "sales_tax_rate": 18,
        "second_sales_tax_rate": 19,
        "sales_tax_status": "TAXABLE",
        "second_sales_tax_status": "TAXABLE",
        "category": "test"
      }
    ]
  }
}

I guess it must be something with category of the product. Probably it cannot be test. Will try to do something with it.

Update: categories seemed to not be required. Removed this row and first invoice was sent. Cool. :slight_smile:

Best regards!