Skip to content
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

REST works, GraphQL returns 404s #760

Open
1 task
czei opened this issue Jan 17, 2025 · 1 comment
Open
1 task

REST works, GraphQL returns 404s #760

czei opened this issue Jan 17, 2025 · 1 comment

Comments

@czei
Copy link

czei commented Jan 17, 2025

Issue summary

This is probably user error, but I didn't know where else to turn for help. 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.

Expected behavior

The sample code should execute an easy GraphQL query:

shopify.resources.GraphQL().execute("{ shop { name id } }")

Actual behavior

urllib.error.HTTPError: HTTP Error 404: Not Found

Steps to reproduce the problem

Run the sample code on a simple shop.

Reduced test case

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"

Can't use sample code "access_token = session.Session.request_token(request_params)"

because request_params aren't defined.

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 } }")


Checklist

  • I have described this issue in a way that is actionable (if possible)
@czei
Copy link
Author

czei commented Jan 17, 2025

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.

To summarize, for the purposes of the python API:

This works: https://ccff42f-x.myshopify.com

This does not work: https://wallywidgets.myshopify.com

The curl commandline call to discover the hidden name was:

curl -v -X POST https://wallywidgets.myshopify.com/admin/api/2025-01/graphql.json -H "Accept: application/json" -H "Content-type: application/json" -H "User-agent: ShopifyPythonAPI/12.7.0 Python/3.13.1" -H "X-shopify-access-token: xxyyzz" -d "{ "query": "{ shop { name id } }" }"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant