Skip to main content
Skip to main content

retrieveCategory - Product Module Reference

Beta

This documentation provides a reference to the retrieveCategory method. This belongs to the Product Module.

This method is used to retrieve a product category by its ID.

Example

A simple example that retrieves a product category by its ID:

import {
initialize as initializeProductModule,
} from "@medusajs/product"

async function retrieveCategory (id: string) {
const productModule = await initializeProductModule()

const category = await productModule.retrieveCategory(id)

// do something with the product category or return it
}

To specify relations that should be retrieved:

import {
initialize as initializeProductModule,
} from "@medusajs/product"

async function retrieveCategory (id: string) {
const productModule = await initializeProductModule()

const category = await productModule.retrieveCategory(id, {
relations: ["parent_category"]
})

// do something with the product category or return it
}

Parameters

productCategoryIdstringRequired
The ID of the product category to retrieve.
The configurations determining how the product category is retrieved. Its properties, such as select or relations, accept the attributes or relations associated with a product category.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<ProductCategoryDTO>Required
The retrieved product category.
Was this section helpful?