Shopify / shopify-api-php

MIT License
391 stars 176 forks source link

HTTPClientFactory Not being setup correctly #103

Closed robjenman closed 2 years ago

robjenman commented 3 years ago

Issue summary

Error thrown: Call to a member function client() on null in /var/www/vendor/shopify/shopify-api/src/Clients/Http.php on line 164

Expected behavior

$client = Context::$HTTP_CLIENT_FACTORY->client(); Should be returning a working Guzzle client however it isnt. Apologies it's late here but Context::initialize() is never called as far as I can see and so $HTTP_CLIENT_FACTORY is never populated with the Guzzle client that is relied on.

Steps to reproduce the problem

  1. Run composer for version 1.0.0
  2. Make a very basic call like new \Shopify\Clients\Rest($url, $accessToken)->get('orders');
robjenman commented 3 years ago

This morning I've seen that buried in your documentations here on Github (Versus not shown in any example on the API reference) is that this is targeted at Partner Apps and not consuming the API as a private app despite that being what is shown on the API reference pages.

As it wouldn't have a app key or secret you can't initialise and this can't be used.

paulomarg commented 3 years ago

Hi @Chutney, in order to make any requests to the Admin API you'll need to call Context::initialize, even if you're using a private app. You can see all of the parameters at https://github.com/Shopify/shopify-php-api/blob/main/docs/getting_started.md, and you'll need to set:

You can see your private app's settings in your Admin:

I'll update the documentation to make it easier to see how to use the api key and password for private apps, thank you for raising this!

chdig commented 3 years ago

Yes, this is quite a major problem for what seems to be the official Shopify Library, and I'd like to request updated documentation as well.

The getting started page doesn't mention private app set up at all.

It seems to imply that there's a long list of parameters to pass as an array to the initialize method, but then the example shows them as arguments instead of parameters. It is not clear which to make. Normally initialize methods take arrays, but this seems not to.

The documentation implies that a session manager object is needed to connect to a private app, using oAuth. In fact, rest calls can be made with normal token/url for private apps. This could be made clearer.

omolto commented 2 years ago

+1

LZL0 commented 2 years ago

Are there any updates regarding this issue?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

github-actions[bot] commented 2 years ago

We are closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.

If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines

Thank you!

faridmovsumov commented 1 year ago

I have the same problem

darius00klokj commented 11 months ago

hey guys,

Call the Context::initialize static function, you will need KEY, SECRET, SCOPES, SHOP NAME and a FileStorageSession. The first 3 you get from the dev app created on your shopify dashboard.

As example

Context::initialize( getenv('SHOP_APP_KEY'), getenv('SHOP_APP_SECRET'), 'read_customers, read_discounts, read_discovery, read_draft_orders, read_assigned_fulfillment_orders, read_merchant_managed_fulfillment_orders, read_order_edits, read_orders, write_orders, read_third_party_fulfillment_orders, read_order_submission_rules', getenv('SHOP_APP_NAME'), new FileSessionStorage('/tmp/php_sessions') );

Run the initialize before your Rest api calls.

conradfr commented 2 months ago

So if you only get the shop name and access token, which is the only data actually necessary to make a query, you can't use this library for no valid reason?

nadar commented 1 month ago

So if you only get the shop name and access token, which is the only data actually necessary to make a query, you can't use this library for no valid reason?

same problem. makes no sense to me

nadar commented 1 month ago

@conradfr

You can do this ugly workaround

Context::$HTTP_CLIENT_FACTORY = new HttpClientFactory;
$client = new Graphql(...,...);