Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
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.
Solved! Go to the solution
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.
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:
Many thanks
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.
Thanks a lot!