Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidArgumentException: invalid length for $contacts when calling GetContactsResponse #355

Open
portbury opened this issue Jul 3, 2024 · 2 comments

Comments

@portbury
Copy link

portbury commented Jul 3, 2024

SDK you're using (please complete the following information):

  • Version 6.0.0

Describe the bug
When testing upgrading to SDK version 6, I am getting unhandled InvalidArgumentException fatal errors when running getContacts().

The issue only occurs if the contact being looked up does not existing in Xero. If the contact does exist in Xero, no exception is thrown.

Full stack trace below:

Uncaught InvalidArgumentException: invalid length for $contacts when calling GetContactsResponse., number of items must be greater than or equal to 1. in /..../app/vendor/xeroapi/xero-php-oauth2/lib/Models/Accounting/GetContactsResponse.php:399

Stack trace:
#0 /..../app/vendor/xeroapi/xero-php-oauth2/lib/AccountingObjectSerializer.php(358): XeroAPI\XeroPHP\Models\Accounting\GetContactsResponse->setContacts(Array)
#1 /..../app/vendor/xeroapi/xero-php-oauth2/lib/Api/AccountingApi.php(28868): XeroAPI\XeroPHP\AccountingObjectSerializer::deserialize(Object(stdClass), '\\XeroAPI\\XeroPH...', Array)
#2 /..../app/vendor/xeroapi/xero-php-oauth2/lib/Api/AccountingApi.php(28811): XeroAPI\XeroPHP\Api\AccountingApi->getContactsWithHttpInfo('38b66c...........', NULL, 'ContactNumber="...', NULL, NULL, 1, true, false, NULL, NULL)
#3 /..../app/wwwroot/includes/pageSections/addressbook/addEdit_form.php(319): XeroAPI\XeroPHP\Api\AccountingApi->getContacts('38b66c..........', NULL, 'ContactNumber="...', NULL, NULL, 1, true)
#4 /..../app/wwwroot/addressbook.php(256): require('/..........')
#5 {main} thrown

To Reproduce
Run the following code to look up a contact in Xero, where the query would ordinarily return zero results:

try {

  $xeroApiInstance = new XeroAPI\XeroPHP\Api\AccountingApi(
    new GuzzleHttp\Client(),
    $xeroApiAuthorisation->getConfig()
  );

  $resultXeroContact = $xeroApiInstance->getContacts($xeroApiAuthorisation->getTenantId(), null, 'ContactNumber="'.$addressbook_id.'"', null, null, 1, true);

  if (!is_null($resultXeroContact) && count($resultXeroContact->getContacts()) == 1) {

    ///Logic to handle the contact details
  }

} catch (\XeroAPI\XeroPHP\ApiException $e) {

  if ($e->getCode() != 404) {

    //handle the exception
  }
}

Expected behavior
A 404 http code should be thrown by XeroAPI\XeroPHP\ApiException in the catch block.

Copy link

github-actions bot commented Jul 3, 2024

PETOSS-458

Copy link

github-actions bot commented Jul 3, 2024

Thanks for raising an issue, a ticket has been created to track your request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant