Shopify JavaScript Buy SDK - 403 error

Solved

Shopify JavaScript Buy SDK - 403 error

palacios000
New Member
4 0 0

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

Screenshot_2022-03-03_18-04-55.png

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

Screenshot_2022-03-03_18-03-48.png

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

Accepted Solution (1)
c10s
Shopify Partner
67 12 27

This is an accepted solution.

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.

View solution in original post

Replies 5 (5)

c10s
Shopify Partner
67 12 27

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

palacios000
New Member
4 0 0

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?

palacios000
New Member
4 0 0

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

c10s
Shopify Partner
67 12 27

This is an accepted solution.

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.

palacios000
New Member
4 0 0

Thanks a lot!