Shopify / storefront-api-examples

Example custom storefront applications built on Shopify's Storefront API
https://help.shopify.com/api/storefront-api
MIT License
1.12k stars 329 forks source link

'SyntaxError: Unexpected end of JSON input' when putting in url and access token #101

Closed mitchellcliftonbarton closed 5 years ago

mitchellcliftonbarton commented 5 years ago

I keep on getting this error after I have replaced the default store url and access token with my own.

Example app listening on port 4200!
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at /Users/welikesmall/pworkspace/storefront-api-examples/node-graphql-client/node_modules/node-fetch/lib/body.js:48:15

    at processTicksAndRejections (internal/process/task_queues.js:85:5)

Here is my 'graphql-js-client.js' file.

import Client from 'graphql-js-client';
import typeBundle from './types';

global.fetch = fetch;

export default new Client(typeBundle, {
  url: 'https://<my-store-name>.myshopify.com/api/2019-07/graphql',
  fetcherOptions: {
    headers: {
      'X-Shopify-Storefront-Access-Token': '<my-access-token>',
      'Content-Type': 'application/json'
    }
  }
});

any ideas?

mitchellcliftonbarton commented 5 years ago

I'm an idiot. I was putting in the wrong access token. SOLVED.

ncuillery commented 1 year ago

In case anyone has this error, and the access token is correct:

For me: that was because the mutations require the header Accept: application/json (not necessary for queries)