Skip to main content
Skip to main content

retrieve - Product Module Reference

Beta

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

This method is used to retrieve a product by its ID

Example

A simple example that retrieves a product by its ID:

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

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

const product = await productModule.retrieve(id)

// do something with the product or return it
}

To specify relations that should be retrieved:

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

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

const product = await productModule.retrieve(id, {
relations: ["categories"]
})

// do something with the product or return it
}

Parameters

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

Returns

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