Error when try to use shopify storefront

Error when try to use shopify storefront

Hg_thomas
Shopify Partner
48 2 2

Hi, 

i try to use shopify storefront api.

So i just want for the moment display the name of the shop in the console but in Chrome i have this error :

Capture d’écran 2021-05-26 à 16.43.34.png

 

here my code :

Index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>Shopify Custom Storefront App</title>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <noscript>
      <strong>We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app">
      <h1 class="page-title">Shopify Custom Storefront App</h1>
    </div>
  </body>
</html>

<script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous">
</script>
<script src="http://sdks.shopifycdn.com/js-buy-sdk/v2/latest/index.umd.min.js"></script>

<script type="module" src="app.js"></script>

 

app.js

const query = `{
    shop {
      name
    }
  }`;
  
 
 
 function apiCall(query) {
    return fetch('kokoprint.myshopify.com/api/graphql.json', {
     method: 'POST',
     headers: {
       'Content-Type': 'application/graphql',
       "Access-Control-Origin": "*",
       'X-Shopify-Storefront-Access-Token': "b4b3ab6921b80585306407746e956e70"
     },
     "body": query
   }).then(response => response.json());
 }
  
 apiCall(query).then(response => {
   console.log(response)
 });

 

Need some help please

ThomasHg
Développeur
Reply 1 (1)

c10s
Shopify Partner
67 12 27

Try changing the 'Content-Type' header to application/json instead of application/graphql