const productQuery = () => `
query {
shop {
products( first: 10) {
edges{
node {
id
handle
title
variants(first: 10){
edges{
node{
title
}
}
}
}
}
}
}
}
`;
const STOREFRONT_ACCESS_TOKEN = "xxxxxxxx"
const GRAPHQL_URL = "https://xxxxxxxxx.myshopify.com/api/2021-10/graphql.json"
const GRAPHQL_BODY = () => {
return {
'async': true,
'crossDomain': true,
'method': 'POST',
'headers': {
'X-Shopify-Storefront-Access-Token': STOREFRONT_ACCESS_TOKEN,
'Content-Type': 'application/graphql',
},
'body': productQuery()
};
}
fetch(GRAPHQL_URL, GRAPHQL_BODY())
.then(res => res.json())
.then(products => {
console.log('products', products)
})
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter