Getting unexpected validation error "Account must be valid/Tax rate must be valid"

84 Views Asked by At

I am trying to make this request through Xero API Explorer

https://api-explorer.xero.com/accounting/invoices/createinvoices?query-unitdp=4

{
  "Invoices": [
    {
      "Type": "ACCREC",
      "Contact": {
        "ContactID": "15976e62-37ad-4065-8bba-d8c5c264e078"
      },
      "LineItems": [
        {
          "Description": "tiered-plan",
          "Quantity": 8555500,
          "UnitAmount": 0.000149611361,
          "AccountCode": "4000",
          "TaxType": "TAX001",
          "taxAmount": 256,
          "ItemCode": "cp_oct17_tiered",
          "LineAmount": 1280
        },
        {
          "Description": "stair-step",
          "Quantity": 8555500,
          "UnitAmount": 0.000029104,
          "AccountCode": "4000",
          "TaxType": "TAX001",
          "taxAmount": 49.8,
          "ItemCode": "cp_oct17_stairstep",
          "LineAmount": 249
        }
      ],
      "Date": "2023-03-11",
      "DueDate": "2022-12-10",
      "Reference": "Website Design",
      "Status": "AUTHORISED"
    }
  ]
}

Getting below validation error:

"ValidationErrors": [
        {
          "Message": "Account must be valid."
        },
        {
          "Message": "Tax rate must be valid."
        }
      ]

This is totally unexpected, as I am using same account and same tax code for other requests as well and all of them getting success.

Later I tried altering content of above request, I updated UnitAmount for second lineItem from "UnitAmount": 0.000029104 to "UnitAmount": 0.0000291

And to my surprise, old validation error gone and now I am getting mismatch error.

New Request

{
  "Invoices": [
    {
      "Type": "ACCREC",
      "Contact": {
        "ContactID": "15976e62-37ad-4065-8bba-d8c5c264e078"
      },
      "LineItems": [
        {
          "Description": "tiered-plan",
          "Quantity": 8555500,
          "UnitAmount": 0.000149611361,
          "AccountCode": "4000",
          "TaxType": "TAX001",
          "taxAmount": 256,
          "ItemCode": "cp_oct17_tiered",
          "LineAmount": 1280
        },
        {
          "Description": "stair-step",
          "Quantity": 8555500,
          "UnitAmount": 0.0000291,
          "AccountCode": "4000",
          "TaxType": "TAX001",
          "taxAmount": 49.8,
          "ItemCode": "cp_oct17_stairstep",
          "LineAmount": 249
        }
      ],
      "Date": "2023-03-11",
      "DueDate": "2022-12-10",
      "Reference": "Website Design",
      "Status": "AUTHORISED"
    }
  ]
}

Response Error

"ValidationErrors": [
        {
          "Message": "The line total 249.00 does not match the expected line total 248.97"
        }
      ]

I would like to know what does Account must be valid / Tax rate must be valid error mean and what was the reason for this error as I am using same account and tax rate for all other requests. Was there some other internal error which is not passed in final response ?

1

There are 1 best solutions below

2
On

The initial error suggests that there is a data mismatch between the tax rate and account code in the payload and those in the tenant you are calling. When using API Explorer, if you have connected more than one tenant and refresh the page, the tenant defaults to the one that is first in the list alphabetically.

The reason that you get a different error when you change the rounding is that the validation is line by line and once an error is found the validation stops and so the account code line is not yet evaluated.

If you are calling the correct tenant, please can you raise a case with Xero Support here with more details of the date and time in UTC and tenant name or id.