Error Handling

If you have an error in your create invoice call, you will receive a JSON Array response where elements of the array reflect errors of the invoices passed in at the same index level. To demonstrate this, we have provided a sample "Batch Create Invoices" endpoint with the following payload:

[{
    "amount_cents2": 20000,
    "discount_amount_cents": 0,
    "invoice_date1": "2021-11-22",
    "invoice_due_date": "2021-11-23",
    "invoice_number": "12346",
    "note": "May’s Annual Tire Order",
    "originating_counterparty_id": "1d71f923-edb3-48a1-aec8-444d75f11f89",
    "receiving_counterparty_id": "b1d5a7e8-62fa-4e38-93bf-6be23bdefa82"
},
{
    "amount_cents": 30000,
    "discount_amount_cents": 0,
    "invoice_date2": "2021-11-22",
    "invoice_due_date": "2021-11-23",
    "invoice_number": "12347",
    "note": "June’s Annual Tire Order",
    "originating_counterparty_id2": "1d71f923-edb3-48a1-aec8-444d75f11f89",
    "receiving_counterparty_id": "b1d5a7e8-62fa-4e38-93bf-6be23bdefa82"
},
{
    "amount_cents": 30000,
    "discount_amount_cents": 0,
    "invoice_date": "2021-11-22",
    "invoice_due_date": "2021-11-23",
    "invoice_number": "123487",
    "note": "June’s Annual Tire Order",
    "originating_counterparty_id": "1d71f923-edb3-48a1-aec8-444d75f11f89",
    "receiving_counterparty_id": "b1d5a7e8-62fa-4e38-93bf-6be23bdefa82"
}]

Invoice #1, with invoice_number 12346, contains 2 errors which are:

  1. Missing "amount_cents' field (renamed to amount_cents2)
  2. Missing "invoice_date" field (renamed to invoice_date1)

Invoice #2, with invoice_number 12347, contains 2 errors which are:

  1. Missing "invoice_date' field (renamed to invoice_date2)
  2. Missing "originating_counterparty_id" field (renamed to originating_counterparty_id2)

Invoice #3 has no errors.

The expected response would be:

[
    {
        "amount_cents": [
            "This field is required."
        ],
        "invoice_date": [
            "This field is required."
        ]
    },
    {
        "invoice_date": [
            "This field is required."
        ],
        "originating_counterparty_id": [
            "This field is required."
        ]
    },
    {}
]

The response returns an array with elements, referencing invoices in the same order they were passed through the system. Note the first and second invoices have 2 errors, while the last invoice has no errors. An empty object represents an invoice without any errors. For error responses, the key/value pairs of the JSON object typically describe the issue encountered. The response key references the API field containing a validation error, while the value contains the failed validation reason.