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.
Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024