Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
I have 20 products and also created a collection filled with products. When I fetch theses products like you see below I get an empty array back...
import Client from 'shopify-buy';
const storeDomain: string = process.env.NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN ?? ''
const accessToken: string = process.env.NEXT_PUBLIC_SHOPIFY_STORE_FRONT_ACCESS_TOKEN ?? ''
// Initializing a client to return content in the store's primary language
const shopifyClient = Client.buildClient({
domain: storeDomain,
storefrontAccessToken: accessToken,
});
const parseShopifyResponse = (response: any) => JSON.parse(JSON.stringify(response));
export { shopifyClient, parseShopifyResponse };
-------------------------------------------------
import type { NextPage } from 'next';
import Layout from 'src/components/Layout';
import { shopifyClient as client, parseShopifyResponse } from 'src/shopify/initialize-js-buy-sdk';
const Home: NextPage = () => {
const resp = async () => {
const products = await client.product.fetchAll(10);
console.log('products', products);
const resp = parseShopifyResponse(products);
console.log('resp', resp);
const collectionsData = await client.collection.fetchAllWithProducts();
console.log('collectionData', collectionsData);
const collections = parseShopifyResponse(collectionsData);
console.log('collections', collections);
}
resp();
return (
<Layout>
<div></div>
</Layout>
);
};
export default Home;
Found the answer.. Had to check available channels in the under products.