Skip to content

getProductsFromCollection(collectionId: number, options?: TGetProductsOptions): Promise<TWebapiList<Product> | null>

The getProductsFromCollection is an asynchronous method that allows to fetch a list of products by their collection id.

Input parameters

collectionId - a number representing the id of the collection.

options - an optional object with additional options for the request. You can read more about TGetProductsOptions object here.

Returned value

A returned value has a type of Promise<TWebapiList<Product> | null>. You can read more about TWebapiList object here.

Example

In this example we make a ProductFetcherApi call to get products from collection with id 1.

useStorefront(async (storefront) => {
    let productFetcherApi = await storefront.getApi('ProductFetcherApi');

    if (!productFetcherApi) {
        const featureSystemApi = storefront.getApiSync('FeatureSystemApi');
        await featureSystemApi.registerDynamic('ProductFetcher');

        productFetcherApi = await storefront.getApi('ProductFetcherApi');
    }

    const products = await productFetcherApi.getProductsFromCollection(1);
    console.log(products);
});

Product Fetcher API methods reference

Objects reference