Unable to create invoice with invoice_items

Im creating an invoice from a Node server sending the payload;

“{“invoice”:{“contact”:“https://testaccount.freeagent.com/contacts/9431993",“dated_on”:“2020-09-06”,“payment_terms_in_days”:0,“invoice_items”:[{“description”:"Reduced Rate VAT”,“quantity”:1,“price”:29.99,“sales_tax_rate”:5}]}}”

but i get an error:

‘invoice_items’ parameter does not match expected type ‘array’

if i dont include the invoice_items parameter if successfully creates the invoice but wont create it with it. p

please help

Hi Daniel,

Ewa here from the Engineering Team at FreeAgent — thanks for your message on our forum and I’ll do my best to help out.

I’ve checked our application logs to take a closer look at your requests and this is the body we’re receiving (I’ve filtered out any potentially sensitive details):

{
  "invoice": {
    "contact": "https://[FILTERED].freeagent.com/contacts/9431993",
    "dated_on": "2020-09-06",
    "payment_terms_in_days": "[FILTERED]",
    "invoice_items": {
      "0": {
        "description": "[FILTERED]",
        "quantity": "1",
        "price": "29.99",
        "sales_tax_rate": "5"
      },
      "1": {
        "description": "[FILTERED]",
        "quantity": "1",
        "price": "20",
        "sales_tax_rate": "5"
      }
    }
  }
}

Based on that, it looks like the value of "invoice_items" is an object rather than array, which would explain the error you encountered. The correct JSON format for this request would read:

{
  "invoice": {
    "contact": "https://[FILTERED].freeagent.com/contacts/9431993",
    "dated_on": "2020-09-06",
    "payment_terms_in_days": "[FILTERED]",
    "invoice_items": [
      {
        "description": "[FILTERED]",
        "quantity": "1",
        "price": "29.99",
        "sales_tax_rate": "5"
      },
      {
        "description": "[FILTERED]",
        "quantity": "1",
        "price": "20",
        "sales_tax_rate": "5"
      }
    ]
  }
}

From your original message it looks like this is what you’re aiming to send, but unfortunately this is not what our server is receiving from your application.

Best wishes,

Ewa