New Shopify Certification now available: Liquid Storefronts for Theme Developers

Fetch data from frontend without using JS-Buy-SDK

PandzAndreas
Shopify Partner
3 0 0

Is it possible to fetch data from the frontend without using JS-Buy-SDK? 

I'm getting cors issues when doing it like this: 

const query = `
{
    products(first: 10) {
      edges {
        cursor
        node {
          id
        }
      }
    }
}
`;

const URL = `https://${storeDomain}/api/2022-04/graphql.json`;

const options = {
  endpoint: URL,
  method: "POST",
  headers: {
    "X-Shopify-Storefront-Access-Token": accessToken,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ query })
}

fetch(URL, options).then((response) => response.json());

 

Reply 1 (1)
steveb3210
Shopify Partner
7 1 1

Try adding "Accept: application/json"