Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Fetch data from frontend without using JS-Buy-SDK

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"