Hey all, sorry if this is a dumb question, but I'm pretty new to shopify app development and I'm currently stuck trying to retrieve the shopID for the merchant store. I have a function that gets triggered by the orders/create webhook, and I need to then be able to get the shopID to then send somewhere else.
I have attached two ideas I have for functions to do this, but I'm currently stuck trying to pass the session object through. Any ideas how I might be able to do this? Otherwise, do you guys know if there are perhaps more elegant solutions that I should try?
I've also thought about adding an api in my index.js file, and trying to call it here instead, but am having trouble getting useAuthenticatedFetch to work.
Thanks in advance!
hi @jomei1 . You can include 'id' in your query to the shop resource in the ADMIN API and this will return the shop_id. https://shopify.dev/docs/api/admin-graphql/2023-07/queries/shop#top, https://shopify.dev/docs/api/admin-graphql/2023-07/objects/Shop#field-shop-id.
Thanks for the response, maybe I'm misunderstanding what the ADMIN API is, but the issue I'm running into is running the query itself, as the GraphQL query seems to require the session object, which my function can't currently access. Any idea how I would be able to do so? And/or how to run a query without requiring the session token to be passed through? Thanks.
Hi @jomei1 ,
Is your app using online access mode when it installs through OAuth?
If it needs to make Admin API requests outside of user sessions, have you considered requesting an offline token in the OAuth flow instead?
Yes, I believe it is. I figured out a solution by creating a session object using the shop object passed through the /api/webhooks call. (Following this example here:
https://workshops.shopify.dev/workshops/webhooks-in-nodejs#8) Thanks again!