joshrps / laravel-shopify-API-wrapper

Interface designed for Shopify apps created with Laravel
MIT License
94 stars 48 forks source link

DATA array for GET requests #30

Open danny-ng opened 6 years ago

danny-ng commented 6 years ago

The example given in README,

$call = $sh->call(['URL' => 'products.json', 'METHOD' => 'GET', 'DATA' => ['limit' => 5, 'published_status' => 'any']]);

doesn't work as it throws this error,

(1/1) ExceptionERROR #22: The requested URL returned error: 400 Bad Request
--
in api.php (line 309)
at API->call(array('URL' => 'products.json', 'METHOD' => 'GET', 'DATA' => array('limit' => 5, 'published_status' => 'published')))in ShopifyController.php (line 59)

I suspect the reason is DATA array is being set to CURLOPT_POSTFIELDS (in api.php) which doesn't seem to be working for GET requests. Updating to this fixes it,

$call = $sh->call([
  'URL' => 'products.json?limit=5&published_status=published', 
  'METHOD' => 'GET', 
]);

Will probably need to rewrite the logic for GET requests where the filtering parameters is appended to the URL endpoint instead of using CURLOPT_POSTFIELDS.

mohdaftab commented 6 years ago

I am facing the same issue and I tried this solution but now getting 403 Forbidden Access

impactcolor commented 6 years ago

Same problem here I just passed the data needed in the url. For example orders.json?limit=5&page=1 as opposed to passing limit = 5 and page = 5 in DATA. I attempted to put in DATA to keep the code as it was but it didn't work.