Bill error: required key bill_items not found on bill

I am using the v2 bills API with the following code:

const credentials = { freeagentRoot: 'api.sandbox' };
const data = {
  contact: `https://${credentials.freeagentRoot}.freeagent.com/v2/contacts/100361`,
  reference: 'TEST001',
  dated_on: '2021-11-29',
  due_on: '2021-12-29',
  bill_items: [
    {
      category: `https://${credentials.freeagentRoot}.freeagent.com/v2/categories/285`,
      description: 'Test',
      total_value: '123.45',
      quantity: '1.0',
    },
  ],
};
const { data: bill } = await axios.post(`https://${credentials.freeagentRoot}.freeagent.com/v2/bills`, data, {
  headers: {
    Authorization: `Bearer ${auth.access_token}`,
  },
});

I get the error as mentioned above: required key bill_items not found on bill - I don’t understand how this can be since I’m sending that array through, it’s just not being picked up.

Any ideas? Thanks!

Scrap that. Worked out it needs to be data = { bill: { foo: 'bar' } }; - missed off a nested bill object

Can I suggest to the devs that the error message body be a bit more descriptive and not try the bill_items validation first? It’s not very helpful as it stands! Thanks

Hey! Thanks for spotting that - we’ve made a note of the issue with the error message and will look into it.

Cheers,
Chris
FreeAgent