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

Address->set() causes API error "address_ids - expected Hash to be a Array"

Open richilton opened this issue 4 years ago • 0 comments

Calling the following code causes the API to return the error address_ids - expected Hash to be a Array (where $address_ids is an associative array of address IDs):

$shopify->Customer($id)->Address->set(['address_ids' => $address_ids, 'operation' => 'destroy']);

This is because http_build_query is including the numeric indexes in the query string (e.g. address_ids[0]=123&address_ids[1]=456). The API is expecting address_ids[]=123&address_ids[]=456.

A possible (if slightly ugly) fix would be to add the following line to CustomerAddress.php after the $url has been generated:

$url = preg_replace('/(address_ids%5B)\d+(%5D)/', '$1$2', $url);

richilton avatar Apr 22 '21 10:04 richilton