This is my first attempt to write code to access Shopify’s admin APIs. Its a bit different in that this will be running on iOT hardware rather than an app plugin, but everything I’ve read said that should work.
This is being written in python using the Shopify python library, with the sample code as a starting point.
So far the examples for the REST version all work fine, so I assume that OAuth has been handled correctly. Deprecating REST is too bad, since that’s all I really need at this point, but that’s going away.
The problem is the sample GraphQL() call returns a 404, which is odd since the REST calls obviously were able to communicate with the store. Here’s the sample code:
from shopify import session
session.Session.setup(api_key=API_KEY, secret=API_SECRET)
shop_url = f"{SHOP_NAME}.myshopify.com"
api_version = '2024-07'
state = binascii.b2a_hex(os.urandom(15)).decode("utf-8")
redirect_uri = f"http://{SHOP_NAME}.myshopify.com/admin/api/2025-01/graphql.json"
scopes = ['read_products', 'read_orders']
newSession = session.Session(shop_url, api_version)
auth_url = newSession.create_permission_url(scopes, redirect_uri, state)
access_token = "XXXXXXX"
newSession = session.Session(shop_url, api_version, access_token)
shopify.resources.ShopifyResource.activate_session(newSession)
# THis works fine
order = shopify.resources.Order.find(5925559599255) # Get a specific order
print(f"Order is: {order.attributes}")
# This gives an error urllib.error.HTTPError: HTTP Error 404: Not Found in graphql.py on line 32:
shopify.resources.GraphQL().execute("{ shop { name id } }")
I hate to ask such a basic question but I’ve been stuck for two days :-(.
Looks like SHOP_NAME is the examples is not in fact the “name” of the shop, but rather an internal name that I couldn’t find anywhere. It wasn’t in the Domain settings for the store.
The format of the “shop name” was revealed in the 301 being returned, which the API erroneously reported as a 404.
“cff42f-x”
It would be nice if the README was updated to make it easier for future customers.
The fact that the customer-facing shop name worked with the REST API calls was a big head scratcher.
If you are building public or private apps, Shopify provide it for you as part of the Auth process so its a bit easier than figuring it out from custom app
Thanks for the help, but I tried that nomenclature and it doesn’t work with my store. I was hopefully explained in the followup, using https://wallywidgets.myshopify.com doesn’t actually work with the GraphQL calls. You have to find out the target of the forward that’s returned, which is in the weird format https://aabbccf2-x.myshopify.com.
When I compared the document code with the code you provided above, I noticed that the redirect URL is incorrectly provided. Please confirm the correct redirect URL (to the application).
session = shopify.Session(shop_url, api_version, access_token)
shopify.ShopifyResource.activate_session(session)
# Note: REST API examples will be deprecated in 2025
shop = shopify.Shop.current() # Get the current shop
product = shopify.Product.find(179761209) # Get a specific product
# GraphQL API example
shopify.GraphQL().execute("{ shop { name id } }")
Thanks for the feedback on the Python library - there’s unfortunately no team owning this currently so we have not been able to update it for platform changes. I’ll connect with our internal teams however with your feedback re: url.
What do you suggest that python users do then? Connect to the GraphQL API directly? You guys might want to mark the python library as unsupported and point developers in the right direction. My only requirement is this particular app has to be in python and just want to get it finished and move on to the next project.
Thanks for trying to help! The redirect URL isn’t used in the code I’m able to get with this library, so it doesn’t really matter. Substituting the API access token from the app’s internal settings successfully bypasses that part of the OAUTH handshake.
In any event, if Shopify has abandoned this library I’ll have to find another way to access account info from python.