searchProducts
Method executing a product search in Salesforce Commerce Cloud.
This method communicates with the searchProducts endpoint of the Vue Storefront API Middleware. In turn, it receives data from the productSearch or the Search Products endpoints exposed by SCAPI / OCAPI, depending on the middleware configuration.
Provides keyword and refinement search functionality for products. The search result contains only products that are online and assigned to site catalog. This resource does not return detailed information about variation products. If a variation product matches the query, basic information for the parent master product is returned. Use the products resource to retrieve more details about a variation product.
Signature
export declare function searchProducts(
props: ProductSearchParams
): Promise<ProductSearchResult>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
props | Required | ProductSearchParams | Parameter object which can be used with this method. Refer to its type definition to learn about possible properties. |
Returns
Returns a representation of a product search result.
Referenced Types
ProductSearchParamsProductSearchResult
Examples
Executing a text-based search using the q parameter.
import { sdk } from '~/sdk.config.ts';
const searchResults = await sdk.commerce.searchProducts({ q: 'red dress' });Getting the third page of products assigned to a specific category using the refine parameter.
import { sdk } from '~/sdk.config.ts';
const categorySearchResult = await sdk.commerce.searchProducts({
refine: ['cgid=exampleCategoryId'],
offset: 24,
limit: 12,
});Using the refine parameter to fetch only orderable products with specified colors and within a specified price range. For demonstration purposes it also uses different than the currently active locale and currency.
import { sdk } from '~/sdk.config.ts';
const category = await sdk.commerce.searchProducts({
locale: 'en_US',
currency: 'USD',
refine: [
'c_refinementColor=red|blue',
'price=(100..500)',
'orderable_only=true',
],
});