Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Getting Started >

Questions regarding creation of Invoice and Line Items via C#?

Started by Lance Alcabasa -   in Getting Started

Hello all, (sorry I'm not sure which to categorize this question)

I am trying to use the Xero API via C# and so far, I have had success. However, I have run on some problems with regards to how to do certain tasks, mainly when creating new Invoices or Line Items.

- how is it possible to add an attachment to a particular Invoice? Or is it even possible to add via the API? if not, I can make do with putting up a Link URL, but I'm not sure where to set it because I am using the Reference = Invoice Number

Line Items - here goes.. many of the problems I have is here
- is it possible to "CREATE" a new Item? What I mean is, when from a browser, I can readily add new Inventory Items easily.. however, when I try to use the API and I try to create a new item with "Item Code" column set-up, it gives me an error "ITEM CODE IS NOT VALID". This only happens if the Item Code DOES NOT EXIST. What I want to do is basically to add a new item with the specified Item Code.

- I need to be able to add Tracking .. Is this even possible from the API? For example, I have a tracking called "Teams", I'd like to be able to set the value or option to be set for this particular Tracking category.

Also, this is just a minor question but, whenever the Total Tax of the Invoice displays correctly when I load the page but when I change one item's tax type, it ALWAYS displays 0 for the Total Tax.. But it still calculates correctly the Invoice Total! I don't know why..

Please help, I would really appreciate it! Thank you!
Best Reply as chosen by Lance Alcabasa (Original Poster)

Here is an example how to create an invoice using a tracking category

Invoice invoiceToCreate = new Invoice {
Contact = new Contact
Name = "ABC Limited"
Type = "ACCREC",
Date = DateTime.Today,
LineItems = new LineItems
new LineItem
AccountCode = "200",
Description = "Blue Widget",
UnitAmount = 10m,
Quantity = 1m,
Tracking = { new TrackingCategory{
Name = "Region",
Option = "North"


The Xero API does not currently support adding notes to invoices. You can keep track of our progress on this on our Uservoice site

Tony Rule (Xero Staff)