GraphQL client not taking available credentials
See original GitHub issueHi there,
I was playing with the brand new GraphQL client embedded in the lib but I noticed that it was not taking the credentials.
Even the Readme suggest that to use the GraphQL step 1-5 are required (getting a token with oath) to work, the doc says otherwise : https://shopify.dev/docs/admin-api/graphql/getting-started
Include the access token as a X-Shopify-Access-Token header in all GraphQL queries and mutations
Non working example:
import shopify
API_KEY = "mykey"
PASSWORD = "mypassword"
website = "mywebsite"
shopify.ShopifyResource.set_site("https://%s:%s@%s.myshopify.com/admin/api/2020-01" % ( API_KEY, PASSWORD, website))
# returns HTTPError: HTTP Error 401: Unauthorized
shopify.GraphQL().execute("{ shop { name id } }")
A simple fix outside of the lib is the following :
# manual fix . shopify.ShopifyResource.password is set by the set_url previous call
shopify.ShopifyResource.headers.update({'X-Shopify-Access-Token': shopify.ShopifyResource.password })
# returns expected data
shopify.GraphQL().execute("{ shop { name id } }")
This does not happen if we create a shopify session and use it :
session = shopify.Session("%s.myshopify.com" % website, "2020-01", PASSWORD)
shopify.ShopifyResource.activate_session(session)
I believe this should be patched in the lib itself at is an easy one. Adding the line :
self.headers.update({'X-Shopify-Access-Token': shopify.ShopifyResource.password })
after https://github.com/Shopify/shopify_python_api/blob/master/shopify/resources/graphql.py#L10 seems to be enough.
I can do the PR if you want even if I believe it might take longer to wait for my PR than committing the fix 😉
Regards
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:7 (3 by maintainers)
Okay, I am going to update the readme. Basically you should not have to use
set_site
and you should definitely not need to set headers yourself. You should just be able to setup your sessions and use them, both temporary and not.Just wanted to comment that this is still an issue as of today. The tutorial is broken for GraphQL + private apps.