Skip to content

getProductsFromCategory(categoryId: number, options?: TGetProductsOptions): Promise | null>

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

Input parameters

productsId - an array of numbers representing the product ids.

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 category with id 1.

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

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

Product Fetcher API methods reference

Objects reference