How can I get an item code from invoices? I'm working on php and I'm trying this
$Code = $invoice->LineItems->ItemCode;
and
$Code = $invoice->LineItems->LineItem->ItemCode;
But that doesn't work. How can I get it then?
Thanks!
LineItems will be an array of LineItem elements, so you need to access the Array element(s) you want the code from:
Loop over all line items:
foreach($invoice->LineItems as $LineItem){
$code = $LineItem->ItemCode;
/* do something with the $code */
}
Or to access the first Line Item:
$code = $invoice->LineItems[0]->ItemCode;
Note, I do all my Xero API work in Python, so I haven't tested this in PHP, apologies if I've made a syntax error, the approach should be sound.