Shopify javascript fetch accessing graphql on 12/18/24

Shopify javascript fetch accessing graphql on 12/18/24

julieker
Shopify Partner
5 0 0

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);
});

Reply 1 (1)

julieker
Shopify Partner
5 0 0

p.s. my token is correct -- I use it elsewhere and it works.   I can fetch from products.json why not api/graphql.json?