getProducts(productsId: number[], options?: TGetProductsOptions): Promise<TWebapiList<Product> | null>¶
The getProducts is an asynchronous method that allows to fetch a list of products by their ids.
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 model here.
Returned value¶
A returned value has a type of Promise<TWebapiList<Product> | null>. You can read more about TWebapiList model here.
Example¶
In this example we make a ProductFetcherApi call to get products with ids 1 and 2.
useStorefront(async (storefront) => {
let productFetcherApi = await storefront.getApi('ProductFetcherApi');
if (!productFetcherApi) {
const featureSystemApi = this.getApiSync('FeatureSystemApi');
await featureSystemApi.registerDynamic('ProductFetcher');
productFetcherApi = await storefront.getApi('ProductFetcherApi');
}
const products = await productFetcherApi.getProducts([1, 2]);
console.log(products);
});