All things Shopify and commerce
I am trying to fetch Product information by 'SKU' from JavaScript. I don't find any option for that. Is that possible just by using Storefront API? If not, Is it possible to use Admin API in the frontend? I don't have any experience with Shopify platform and trying to figure out best way to fetch product by 'SKU'. Below is my JavaScript code:
const STOREFRONT_ACCESS_TOKEN = 'xxxxxxxxxxxxxx';
const GRAPHQL_URL = 'https://<mystore>.myshopify.com/api/2021-01/graphql.json';
// NOT WORKING
const query = `productByHandle(handle:"sku:xxxx") {
id
title
description
}`;
const GRAPHQL_BODY = {
'method': 'POST',
'headers': {
'X-Shopify-Storefront-Access-Token': STOREFRONT_ACCESS_TOKEN,
'Content-Type': 'application/json',
},
'body': JSON.stringify({ query })
}
fetch(GRAPHQL_URL , GRAPHQL_BODY )
.then(res => res.json())
.then(data => {
return(data);
})
.catch((error) => {
return(error);
});
query($filter: String!) {
products(first: 1, query: $filter) {
edges {
node {
id
title
handle
}
}
}
}
{
"filter": "sku:1111111111"
}
I believe this answer is incorrect. In my testing I couldn't get it to work, it seems that it is only possible to query product by SKU using Admin API, not Storefront API.
2m ago Learn the essential skills to navigate the Shopify admin with confidence. T...
By Shopify Feb 12, 2025Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025