-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic CRUD GET for DiscountCode fails #36
Comments
Can you try |
I tried that also, same result. Sorry for not mentioning it earlier. Here is a stack trace: #0 .../vendor/slince/shopify-api-php/src/Client.php(338): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined offse...', '/...', 338, Array) |
So I found out what is the problem, as the docs say
So I'm guessing on the redirect the client is not sending the access token, and that is why we get a script to redirect for authentication. And the exception, cause it can't read html. Maybe this is out of the scope of the SDK. Here is the code I used to extract the header, which by the way is containing the price rule and coupon ids, which I will use to make another call and get the required data. Sorry for the messy code.
|
I tried to figure out the problem, and here's what I came up with. In my opinion, the problem is really related to the redirection, but it is related to the fact that the API returns Location header without specifying the type. For example, we have a request:
API returns:
URL, which is given in Location, has no suffix .json, Guzzle passes on this Location, then API redirects us to /admin/auth/login, where Shopify already return HTML page, but not the answer from API. Similar to the request:
I think this problem would be solved if the request for redirection were to be executed not to:
but to: /admin/price_rules/3837494040555/discount_codes/2393875330.json In this case, the requested JSON object is returned without additional redirect to /admin/auth/login. @shaldev Guzzle library is used for HTTP requests and all headers (including X-Shopify-Access-Token) that were sent to the original request, except for some cases, are sent when redirecting. I checked this with the debug option. Also see: guzzle/guzzle#1272 (comment) |
Thanks for the detailed answer @maximzasorin |
Keep it, I believe there should be a better solution; I will try to improve the problem later. |
I'm trying to do a custom get request to the following endpoint: /admin/api/2019-04/discount_codes/lookup.json
$client->get('api/2019-04/discount_codes/lookup', [ 'code' => $query ]);
But I receive an error:
I've made the same request using a browser (BasicAuth) and it returns a result. But it does some redirect, maybe this is the problem. Anyone had a similar issue? Thanks.
The text was updated successfully, but these errors were encountered: