I am wondering why I get the error
Extensions Unauthorized when I am trying to fetch a simple graphql query. I am fetching from
/api/2024-10/graphql.json.. Please advise… you should be able to do this fetch from main-products.liquid. My code is below – ignore the debugging alert messages: I have checked my graphql query … it ran successfully through graphql…
fetch(‘/api/2024-10/graphql.json’, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
‘X-Shopify-Storefront-Access-Token’: ‘xxxx’
},
body: JSON.stringify({
query: `
{
productVariant(id: “gid://shopify/ProductVariant/123”)
{
id
title
}
}
`
})
})
.then(response => response.json())
.then(data => {
// Handle the product data
alert (‘in ZZZZZZZZZ product product data…’);
alert(‘HEY ZZZZZ data:’ + JSON.stringify(data));
alert (‘ZZZZZZZZZZafter product product data’);
})
.catch(error => {
// Handle errors
alert (‘ZZZZZZZZZin product product error…’ + error);
console.error(error);
});