XeroAPI / xero-php-oauth2

Xero PHP SDK for oAuth 2 generated from Xero API OpenAPI Spec 3.0
MIT License
91 stars 65 forks source link

Getting list of accounts as an array #224

Closed Aniruddh-J closed 3 years ago

Aniruddh-J commented 3 years ago

Hello,

Is it possible to get the list of accounts as an array instead of instances of XeroAPI\XeroPHP\Models\Accounting\Accounts\Account?

Typecasting adds array of *container.

Any suggestions?

SidneyAllen commented 3 years ago

Hi @Aniruddh-J

Not sure if this is what you are looking for, but the following code allows you to loop over array of objects.

$allContacts = $apiInstance->getContacts($xeroTenantId);

foreach($allContacts as $contact) { 
    echo($contact->getName());
}

Let us know if this answers your question.

SidneyAllen commented 3 years ago

@Aniruddh-J - I didn't hear back, so assuming this answered your question. Closing issue now :-)

Aniruddh-J commented 3 years ago

Sorry for the late response. I was able to loop through the accounts just the way you looped through contacts in your code. :)