xero-php icon indicating copy to clipboard operation
xero-php copied to clipboard

rawurlencode() expects parameter 1 to be string

Open DeweyOx opened this issue 5 years ago • 9 comments

When using:

$xero->loadByGUIDs(Invoice::class, $ids);

Where $ids is an array of invoice numbers...

You get the error:

rawurlencode() expects parameter 1 to be string, array given in /vendor/calcinai/xero-php/src/XeroPHP/Helpers.php on line 209

Any idea how to solve this?

DeweyOx avatar Dec 04 '19 21:12 DeweyOx

@DeweyOx are you certain that $ids isn't an array of arrays?

calcinai avatar Dec 04 '19 21:12 calcinai

Yes. Just debugged it:

array(5) {
  [0] => '1181'
  [1] =>  'INV-0027'
  [2] => 'INV-0028'
  [3] => '1171'
  [4] => 'SI-2'
}

DeweyOx avatar Dec 04 '19 21:12 DeweyOx

If i use '@' to suppress warnings, it works. But I can't be using that on production.

DeweyOx avatar Dec 04 '19 21:12 DeweyOx

@DeweyOx Just checked out the Xero docs, they expect a comma-separated string of ids...

IDs, InvoiceNumbers, ContactIDs, Statuses | Filter by a comma-separated list of InvoicesIDs, InvoiceNumbers, ContactIDs or Statuses.

calcinai avatar Dec 04 '19 21:12 calcinai

The library should probably be smart enough to implode these for you...

calcinai avatar Dec 04 '19 21:12 calcinai

it was the first thing I tried, but it fails with this lib. Any workarounds?

DeweyOx avatar Dec 04 '19 22:12 DeweyOx

What does it do, I assume you're doing something like this?

$xero->loadByGUIDs(Invoice::class, implode(',', $ids);

calcinai avatar Dec 04 '19 22:12 calcinai

exactly, but I get: array(2) { 'success' → bool:false 'msg' → str(11) 'Bad Request' }

DeweyOx avatar Dec 04 '19 22:12 DeweyOx

I changed Request.php to read: public function setParameter($key, $value) { if(is_array($value)) { $value = implode(',', $value); } $this->parameters[$key] = $value; return $this; }

but I get the same Bad Request

DeweyOx avatar Dec 04 '19 22:12 DeweyOx