Empty response from GraphQL

Highlighted
New Member
3 0 0

I am trying to use graphQL to get the first 10 products and show this in the console. 

 

The code I'm using is

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

}`;

fetch("https://portabello-uk.myshopify.com/api/2020-07/graphql", {
  method: "POST",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/graphql",
    "X-Shopify-Storefront-Access-Token": "eab72f9ec5900559dd3bd4ace8d4e89f",
  },
  body: query,
})
.then((response) => response.json())
.then((response) => {
  console.log(response);
})
.catch((error) => console.error(error));

 When I run this, there is no data. Even though the request works in the shopify GraphiQL app.

Does anyone know how to get the response and log it in the console?

0 Likes