Retrieving an empty products array with JS-Buy-SDK

PandzAndreas
Shopify Partner
3 0 0

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;

 

Reply 1 (1)

PandzAndreas
Shopify Partner
3 0 0

Found the answer.. Had to check available channels in the under products.