Shopify JavaScript Buy SDK - 403 error

Hi, I’m trying to following your documentation for the JavaScript Buy SDK (here) but I’m not able to get all products.

My code is

<script src="http://sdks.shopifycdn.com/js-buy-sdk/v2/latest/index.umd.min.js"></script>

<script>
// Initialize the client
var client = ShopifyBuy.buildClient({
domain: 'perroslife.myshopify.com',
storefrontAccessToken: 'shpat_xxxxxxxxxxxxxxxxxxxxxxe01c'
});
console.log(client); // I get a response

client.product.fetchAll().then((products) => {
console.log(products); // I get errors
});
</script>

This is the browser console

I don’t think it’s an authentication issue, as I’m using the access token provided during app creation:

Thanks for help, and sorry if my JS skills are bit basic.

Looks like you might be using an Admin API token and not one for the Storefront API.

Hi, thanks for help.Sorry I’m a bit confused… If I use the above token with PHP or curl, I get the products as expected. Instead with Js Buy SDK I can’t make it work. That’s why I think the token is correct. Shall I leave the JS Buy SDK and use curl instead?

I’ve read the documentation more then twice and still information is not clear… So if anyone can answer these question would be much appreciated:

  1. In order to have a JS Buy SDK, I have to create an app from partners.shopify.com?
  2. If I chose a private app (from partners.shopify.com), then it mus be authenticated via OAuth?

Many thanks

If it’s for a single shop you can create a private app, when doing so the very bottom of the private app page you’ll see a “Storefront API” section. The token provided there is what you need for the JS Buy SDK. The Buy SDK is just a wrapper around the Storefront API.

I’ve attached an image as a reference for the token you need.

Thanks a lot!