Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Endpoints >

Line total mismatch on invoice line that has not been updated

Started by Invoice Sherpa -   in API Endpoints

I'm trying to append a new line to an invoice. My process is:

1. retrieve the invoice to be updated;
2. append a new line;
3. POST the invoice with the new line back to Xero.

The line items look roughly like this:

This code is provided by the developer community - Xero does not warrant it in any way

As indicated in the line descriptions, the first line is one I retrieved from Xero, while the second line is the new line I'm trying to append.

When I make my update request, I get the following message: "the line total 1500.00 does not match the expected line total 1499.93, and 3 other issues." I understand that this happens when the `LineAmount` does not match the amount computed by Xero given the line's item and quantity. However, the amount indicated in the error belongs to a line that I have not altered. In other words, 1500.00 appears to be the amount computed by Xero, but Xero does not accept it when I post it back.

How do I get around this? I would prefer not to cause Xero to recalculate totals on lines I haven't updated, if possible.
Turns out this is due to the DiscountRate. When validating the update request, Xero uses the DiscountRate to calculate the DiscountAmount. The trouble is that Xero rounds the DiscountRate to the nearest hundredth, so the resulting amount is off by a few cents. Consequently, you can retrieve and post a totally unaltered invoice, and Xero will reject it.

Since keeping the amount as-is was more important than preserving the rate, I omitted the rate from my request and let Xero recalculate it (it comes out to the same rounded amount in the response anyway). This resolved the issue.

Invoice Sherpa