Ecommerce Shopify WordPress Discussion

How to get the globally unique identifier of a Shopify store using GraphQL

I am trying to get the shopID using a GraphQL. I can get the value using a GraphQL app but when I run the query through a function I get null. export async function getShopId(admin) { // Your GraphQL query to get the shop ID const GET_SHOP_ID = ` { shop { id } } `; try { // Execute the GraphQL query using the admin object const { data, errors } = await admin(GET_SHOP_ID); if (errors) { // Handle errors if the query fails console.error('Error fetching shop ID:', errors); return null; } // Access the shop ID from the query response const shopId = data?.shop?.id; console.log(data); if (!shopId) { // Handle the case where shop ID is not available console.error('Shop ID not found in the GraphQL response.'); return null; } return shopId; } catch (error) { console.error('Error in getShopId:', error); return null; } } I am calling this function through a loader so the admin and the graphql should exist but I keep getting null. Here is the loader export async function loader({ request, params }) { const { admin, session } = await authenticate.admin(request); const { shop } = session; const graphql = admin.graphql; // Example: Fetching shop ID using getShopId const shopIdm = await getShopId(graphql); console.log("shopId-->" + shopIdm); return null }
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.