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

getCategory

Method fetching information about a specific category from SAP Commerce Cloud.

This method send a GET request to the getCategory endpoint of the Alokai Middleware. In turn, it receives data from the getCategories endpoint exposed by the SAP OCC API Catalogs Controller.

You can use this method to fetch information about a category available in the Catalog Version used by the current Base Store.

Signature

export declare function getCategory<Res extends CategoryHierarchy = CategoryHierarchy,
	Props extends GetCategoryProps = GetCategoryProps>(
	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 Category Hierarchy.

Referenced Types

Examples

Fetching a category by id.

import { sdk } from '~/sdk';

const category = await sdk.commerce.getCategory({ id: 'collections' });

Using the method the way it will be possible to cache the response.

import { sdk } from '~/sdk';

const category = await sdk.commerce.getCategory({ id: 'collections', lang: 'en', currency: 'GBP' });

Fetching a category by id and selecting response fields.

import { sdk } from '~/sdk';

const category = await sdk.commerce.getCategory({ id: 'collections', fields: 'id,name,url' });

On this page