Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > SDKs >

Lost line item tax codes using Create or Update invoices via Xero API / SDK

Started by Lesley Aitchison -   in SDKs

We have an AWS lambda function (.js) that is successfully creating invoices and their lineitems in xero using the xero api / node sdk (xero.accountingApi.createInvoices()). We specify a code for a custom tax rate on these line items which appears correctly on the invoice in xero.
However when using:
xero.accountingApi.updateOrCreateInvoices(activeTenantId, updatedInvoice);
to update our api created pre-existing unapproved invoices we find that we can successfully remove and/or add one or more invoice line items, and any new items correctly have the custom taxrate, however the pre-existing/old line items on the invoice all lose their custom taxrate (reverts to account level code). I don't believe these records are included in the method call so why do they change and lose their tax codes?
Please let me know if I've missed something obvious or happy to provide sample code if you can let me know what is relevant.
Hi Lesley,

LineItems can be a bit tricky.
I'm just going to quickly restate what I think you're saying is happening to make sure we're on the same page:
1. You create an invoice with one or more line items that have TaxAmount manually set to a value e.g. the tax type on the line item is 'NONE' but you're setting the TaxAmount to '20.0' for example
2. You update that invoice to add or remove a LineItem
3. You lose the TaxAmount that was manually set on the other existing LineItems

Is that correct? Or is it the TaxType that you're manually setting on the LineItem rather than TaxAmount?

Steven Brown (Xero Staff)  

Thanks for replying.

All correct, but its TaxType, not TaxAmount.

Lesley Aitchison  

So I've had a play around with the api-explorer and it looks like the only way this would happen is if the existing lineitem was being sent in with the TaxType missing from the data contract.

I've had a look at the code for the SDK and it looks like it's simply passing the invoice provided straight through in the updateOrCreateInvoices so I don't think it's being stripped out by that method. I'm not a node developer however so I could be missing something.

If it's possible for you to debug things and see if whatever path you're providing the invoice to be updated is passing through the TaxType then we could go from there. If we find that it does exist then I'll chase it up with the maintainers of the SDK. Let me know if there is any more info you need to make progress on this

Steven Brown (Xero Staff)