Skip to content

Accounting API getInvoices fails when where condition results in no rows returned #356

@atf2

Description

@atf2

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

  • Version 6.0.0

Describe the bug
A call to getInvoices throws an exception if the where condition results in no rows being returned. This was not the case in V5

e.g.
$accountingApi = new \XeroAPI\XeroPHP\Api\AccountingApi( new \GuzzleHttp\Client(),
$xeroApiAuthorisation->getConfig() );
$r = $accountingApi()->getInvoices( $xeroApiAuthorisation->tenantId(), null, "1 = 2", null, null, null, null, null, 1 );
$arr = $r->getInvoices();

Results

To Reproduce
Run the following code:

$accountingApi = new \XeroAPI\XeroPHP\Api\AccountingApi( new \GuzzleHttp\Client(),
$xeroApiAuthorisation->getConfig() );
$r = $accountingApi()->getInvoices( $xeroApiAuthorisation->tenantId(), null, "1 = 2", null, null, null, null, null, 1 );
$arr = $r->getInvoices();

An exception is throw in the call from the second line "$r = ..." with the message
"( ! ) InvalidArgumentException: invalid length for $invoices when calling GetInvoicesResponse., number of items must be greater than or equal to 1. in {edited}\vendor\xeroapi\xero-php-oauth2\lib\Models\Accounting\GetInvoicesResponse.php on line 399"

The trace ends:
XeroAPI\XeroPHP\Api\AccountingApi->getInvoicesWithHttpInfo( $xero_tenant_id = 'cd1a68e0-d5aa-479d-a86c-1a81ded061ff', $if_modified_since = NULL, $where = '1 = 2', $order = NULL, $ids = NULL, $invoice_numbers = NULL, $contact_ids = NULL, $statuses = NULL, $page = 1, $include_archived = NULL, $created_by_my_app = NULL, $unitdp = NULL, $summary_only = FALSE, $page_size = NULL ) | ...\AccountingApi.php:34315
XeroAPI\XeroPHP\AccountingObjectSerializer::deserialize( $data = '{\r\n "Id": "6426bbb0-b18d-4afa-a595-c58b310660c9",\r\n "Status": "OK",\r\n "ProviderName": "Oatlands Test",\r\n "DateTimeUTC": "\/Date(1720196319232)\/",\r\n "Invoices": []\r\n}', $class = '\XeroAPI\XeroPHP\Models\Accounting\GetInvoicesResponse', $httpHeaders = [] ) | ...\AccountingApi.php:34376
XeroAPI\XeroPHP\Models\Accounting\GetInvoicesResponse->setInvoices( $invoices = [] ) | ...\AccountingObjectSerializer.php:358

Expected behavior
$r is set to a getInvoicesResponse object containing an empty array of invoices.

Additional context
This works as expected in V4.0.0 and v5.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions