dcblogdev / laravel-xero

Laravel package for working with Xero API
Other
41 stars 25 forks source link

Parameters not working when fetching invoices #37

Closed hirani89 closed 8 months ago

hirani89 commented 1 year ago

Hi,

I have been using this library for over a year now. For some reason, things started to fail with error cURL error 18: transfer closed with 227443 bytes remaining to read

After updating from v1.1.1 to v1.1.5, stopped getting that error. But request parameters are not working anymore.

Xero::invoices()->get(10, 'Type="ACCREC"') returns all invoices including ACCPAY and it also returns all invoices. Changing the page makes no difference either.

When I send https://api.xero.com/api.xro/2.0/invoices?page=10&where=Type%3D%22ACCREC%22 using insomnia, correct results are returned.

I tried this on my local environment and prod as well.

hirani89 commented 1 year ago

Below are the contents of $response at line 260 of vendor/dcblogdev/laravel-xero/src/Xero.php

Illuminate\Http\Client\Response::__set_state(array(
   'response' => 
  GuzzleHttp\Psr7\Response::__set_state(array(
     'reasonPhrase' => 'OK',
     'statusCode' => 200,
     'headers' => 
    array (
      'Content-Type' => 
      array (
        0 => 'application/json; charset=utf-8',
      ),
      'Content-Length' => 
      array (
        0 => '9175707',
      ),
      'Server' => 
      array (
        0 => 'nginx',
      ),
      'Xero-Correlation-Id' => 
      array (
        0 => '55118053-42ee-4c6f-8862-8379895bc1d0',
      ),
      'X-AppMinLimit-Remaining' => 
      array (
        0 => '9970',
      ),
      'X-MinLimit-Remaining' => 
      array (
        0 => '52',
      ),
      'X-DayLimit-Remaining' => 
      array (
        0 => '4456',
      ),
      'Expires' => 
      array (
        0 => 'Thu, 27 Jul 2023 12:21:11 GMT',
      ),
      'Cache-Control' => 
      array (
        0 => 'max-age=0, no-cache, no-store',
      ),
      'Pragma' => 
      array (
        0 => 'no-cache',
      ),
      'Date' => 
      array (
        0 => 'Thu, 27 Jul 2023 12:21:11 GMT',
      ),
      'Connection' => 
      array (
        0 => 'keep-alive',
      ),
      'X-Client-TLS-ver' => 
      array (
        0 => 'tls1.2',
      ),
    ),
     'headerNames' => 
    array (
      'content-type' => 'Content-Type',
      'content-length' => 'Content-Length',
      'server' => 'Server',
      'xero-correlation-id' => 'Xero-Correlation-Id',
      'x-appminlimit-remaining' => 'X-AppMinLimit-Remaining',
      'x-minlimit-remaining' => 'X-MinLimit-Remaining',
      'x-daylimit-remaining' => 'X-DayLimit-Remaining',
      'expires' => 'Expires',
      'cache-control' => 'Cache-Control',
      'pragma' => 'Pragma',
      'date' => 'Date',
      'connection' => 'Connection',
      'x-client-tls-ver' => 'X-Client-TLS-ver',
    ),
     'protocol' => '1.1',
     'stream' => 
    GuzzleHttp\Psr7\Stream::__set_state(array(
       'stream' => NULL,
       'size' => NULL,
       'seekable' => true,
       'readable' => true,
       'writable' => true,
       'uri' => 'php://temp',
       'customMetadata' => 
      array (
      ),
    )),
  )),
   'decoded' => NULL,
   'cookies' => 
  GuzzleHttp\Cookie\CookieJar::__set_state(array(
     'cookies' => 
    array (
    ),
     'strictMode' => false,
  )),
   'transferStats' => 
  GuzzleHttp\TransferStats::__set_state(array(
     'request' => 
    GuzzleHttp\Psr7\Request::__set_state(array(
       'method' => 'GET',
       'requestTarget' => NULL,
       'uri' => 
      GuzzleHttp\Psr7\Uri::__set_state(array(
         'scheme' => 'https',
         'userInfo' => '',
         'host' => 'api.xero.com',
         'port' => NULL,
         'path' => '/api.xro/2.0/invoices',
         'query' => '',
         'fragment' => '',
         'composedComponents' => 'https://api.xero.com/api.xro/2.0/invoices',
      )),
       'headers' => 
      array (
        'User-Agent' => 
        array (
          0 => 'GuzzleHttp/7',
        ),
        'Host' => 
        array (
          0 => 'api.xero.com',
        ),
        'Authorization' => 
        array (
          0 => 'Bearer eyJhbGciOiJSUzI1NiIsImtpZ',
        ),
        'Xero-tenant-id' => 
        array (
          0 => 'xxxxxxxx-xxxx-xxxx-xxxx-be11324d9b4f',
        ),
        'Accept' => 
        array (
          0 => 'application/json',
        ),
      ),
       'headerNames' => 
      array (
        'user-agent' => 'User-Agent',
        'host' => 'Host',
        'authorization' => 'Authorization',
        'xero-tenant-id' => 'Xero-tenant-id',
        'accept' => 'Accept',
      ),
       'protocol' => '1.1',
       'stream' => 
      GuzzleHttp\Psr7\Stream::__set_state(array(
         'stream' => NULL,
         'size' => 0,
         'seekable' => true,
         'readable' => true,
         'writable' => true,
         'uri' => 'php://temp',
         'customMetadata' => 
        array (
        ),
      )),
    )),
     'response' => 
    GuzzleHttp\Psr7\Response::__set_state(array(
       'reasonPhrase' => 'OK',
       'statusCode' => 200,
       'headers' => 
      array (
        'Content-Type' => 
        array (
          0 => 'application/json; charset=utf-8',
        ),
        'Content-Length' => 
        array (
          0 => '9175707',
        ),
        'Server' => 
        array (
          0 => 'nginx',
        ),
        'Xero-Correlation-Id' => 
        array (
          0 => '55118053-42ee-4c6f-8862-8379895bc1d0',
        ),
        'X-AppMinLimit-Remaining' => 
        array (
          0 => '9970',
        ),
        'X-MinLimit-Remaining' => 
        array (
          0 => '52',
        ),
        'X-DayLimit-Remaining' => 
        array (
          0 => '4456',
        ),
        'Expires' => 
        array (
          0 => 'Thu, 27 Jul 2023 12:21:11 GMT',
        ),
        'Cache-Control' => 
        array (
          0 => 'max-age=0, no-cache, no-store',
        ),
        'Pragma' => 
        array (
          0 => 'no-cache',
        ),
        'Date' => 
        array (
          0 => 'Thu, 27 Jul 2023 12:21:11 GMT',
        ),
        'Connection' => 
        array (
          0 => 'keep-alive',
        ),
        'X-Client-TLS-ver' => 
        array (
          0 => 'tls1.2',
        ),
      ),
       'headerNames' => 
      array (
        'content-type' => 'Content-Type',
        'content-length' => 'Content-Length',
        'server' => 'Server',
        'xero-correlation-id' => 'Xero-Correlation-Id',
        'x-appminlimit-remaining' => 'X-AppMinLimit-Remaining',
        'x-minlimit-remaining' => 'X-MinLimit-Remaining',
        'x-daylimit-remaining' => 'X-DayLimit-Remaining',
        'expires' => 'Expires',
        'cache-control' => 'Cache-Control',
        'pragma' => 'Pragma',
        'date' => 'Date',
        'connection' => 'Connection',
        'x-client-tls-ver' => 'X-Client-TLS-ver',
      ),
       'protocol' => '1.1',
       'stream' => 
      GuzzleHttp\Psr7\Stream::__set_state(array(
         'stream' => NULL,
         'size' => NULL,
         'seekable' => true,
         'readable' => true,
         'writable' => true,
         'uri' => 'php://temp',
         'customMetadata' => 
        array (
        ),
      )),
    )),
     'transferTime' => 3.188977,
     'handlerStats' => 
    array (
      'url' => 'https://api.xero.com/api.xro/2.0/invoices',
      'content_type' => 'application/json; charset=utf-8',
      'http_code' => 200,
      'header_size' => 441,
      'request_size' => 1625,
      'filetime' => -1,
      'ssl_verify_result' => 0,
      'redirect_count' => 0,
      'total_time' => 3.188977,
      'namelookup_time' => 0.004906,
      'connect_time' => 0.018075,
      'pretransfer_time' => 0.072123,
      'size_upload' => 0.0,
      'size_download' => 9175707.0,
      'speed_download' => 2878201.0,
      'speed_upload' => 0.0,
      'download_content_length' => 9175707.0,
      'upload_content_length' => -1.0,
      'starttransfer_time' => 1.236819,
      'redirect_time' => 0.0,
      'redirect_url' => '',
      'primary_ip' => '23.214.108.200',
      'certinfo' => 
      array (
      ),
      'primary_port' => 443,
      'local_ip' => '192.168.0.116',
      'local_port' => 52519,
      'http_version' => 2,
      'protocol' => 2,
      'ssl_verifyresult' => 0,
      'scheme' => 'HTTPS',
      'appconnect_time_us' => 71962,
      'connect_time_us' => 18075,
      'namelookup_time_us' => 4906,
      'pretransfer_time_us' => 72123,
      'redirect_time_us' => 0,
      'starttransfer_time_us' => 1236819,
      'total_time_us' => 3188977,
      'appconnect_time' => 0.071962,
    ),
     'handlerErrorData' => 0,
  )),
))

As you can see under transferStats, the value of query is empty. Should it be like that?

In the response I get some 5200 invoices regardless of what page number is supplied. This is the same I get when I send https://api.xero.com/api.xro/2.0/invoices using insomnia/postman.

hirani89 commented 1 year ago

Changing $result = Xero::get('invoices?'.$params); to $result = Xero::get('invoices',$params); in src/Resources/Invoices.php seems to fix the problem.

mattglover11 commented 1 year ago

Can you give me an example of your $params? Anything I use returns all invoice types and all statuses

tonypartridger commented 8 months ago

Close due to none comment. I suspect params is now an array which is why it was failing previously as it was a string.