Shopify javascript fetch accessing graphql on 12/18/24

Topic summary

A developer is encountering an “Extensions Unauthorized” error when attempting to fetch GraphQL data from Shopify’s /api/2024-10/graphql.json endpoint within a main-products.liquid file.

Key Details:

  • The GraphQL query runs successfully when tested directly through Shopify’s GraphQL interface
  • The fetch request includes proper headers (Content-Type: application/json and X-Shopify-Storefront-Access-Token)
  • The access token is verified as correct and works in other contexts
  • The code appears to contain debugging alert messages to track the response flow

Current Status:

  • The developer can successfully fetch from /products.json but not from the GraphQL endpoint
  • The issue remains unresolved with no responses yet
  • The authorization error suggests a potential permissions or authentication configuration problem specific to the GraphQL API endpoint
Summarized with AI on November 3. AI used: claude-sonnet-4-5-20250929.

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

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