XeroAPI/XeroAPI.Net

Trying to Add TrackingCategory Value to Invoice Line C#

Opened this issue · 0 comments

I am trying to add TrackingCategory value to invoice line and I receive an error "Object reference not set to an instance of an object).

` LineItem li = new LineItem();
li.LineAmount = inv.LineItems[i].LineAmount;
li.ItemCode = inv.LineItems[i].ItemCode;
li.Description = inv.LineItems[i].Description;
li.AccountCode = inv.LineItems[i].AccountCode;
li.UnitAmount = inv.LineItems[i].UnitAmount;
var categories = inv.Categories.Where(c => c.TicketChargeLineId == inv.LineItems[i].TicketChargeLineId);
foreach(var c in categories)
{
if(c.Value != "")
{
li.Tracking = new ItemTracking();

                            ItemTrackingCategory tc = new ItemTrackingCategory();
                            tc.Name = c.Name;
                            tc.Id = c.Id;
                            tc.Option = c.Value;
                            li.Tracking.Add(tc);
                          
                        }

                    }
                    
					lineItems.Add(li);

`
It seems to work but when I look at the invoices in Xero, the Tracking Category fields are blank.