Alokai
You are reading the documentation for v7.x and earlier, which is no longer the latest version. Switch to v8.x

getProductsByCategory

Method fetching a list of products filtered by category and additional filters.

This method sends a GET request to the getProductsByCategory endpoint of the Alokai Middleware. In turn, it receives data from the getProductsByCategory endpoint exposed by the SAP OCC API B2B Categories Controller.

In the examples below, you can see how various parameter configurations passed to the SDK method affect the final query parameter sent to the SAP OCC API.

Signature

export declare function getProductsByCategory<Res extends ProductSearchPage = ProductSearchPage,
	Props extends GetProductsByCategoryProps = GetProductsByCategoryProps>(
	props: Props,
	options?: MethodOptions
): Promise<Res>;

Parameters

NameRequiredTypeDescription
propsRequiredPropsParameter object which can be used with this method. Refer to its type definition to learn about possible properties.
optionsOptionalMethodOptionsOptions that can be passed to additionally configure the request or customize the logic in a plugin.

Returns

Returns a representation of a Product Search Page. That includes products and additional data, such as available facets, sorting and pagination options. It can also include spelling suggestions.

Referenced Types

Examples

Using the method without any parameters to fetch unfiltered products and additional data.

Final query: :undefined

import { sdk } from '~/sdk';

const result = await sdk.commerce.getProductsByCategory({ categoryId: '1'});

Fetching paginated products and additional data by using the pageSize and currentPage parameters.

import { sdk } from '~/sdk';

const result = await sdk.commerce.getProductsByCategory({ categoryId: '1', lang: 'en', currency: 'GBP', pageSize: 10, currentPage: 1 });

Performing a free-text search and sorting the results by using

import { sdk } from '~/sdk';
const query = 'sneakers:topRated';
const result = await sdk.commerce.getProductsByCategory({ categoryId: '1', query, sort: 'topRated' });

Performing a free-text search and selecting response fields by using fields parameters. The response object will only contain the freeTextSearch key (alongside type and pagination which are always included - regardless of specified fields).

import { sdk } from '~/sdk';

const query = `sneakers:undefined`;
const result = await sdk.commerce.getProductsByCategory({ categoryId: '1', query, fields: 'freeTextSearch' });

On this page