-1

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!

Kim Doe
  • 3
  • 1
  • 11

2 Answers2

0

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.

Cameron Roberts
  • 7,127
  • 1
  • 20
  • 32
0

A paged request was necessary to get the Item Code field.

Kim Doe
  • 3
  • 1
  • 11