retrieveVariant - Product Module Reference
BetaThis documentation provides a reference to the retrieveVariant method. This belongs to the Product Module.
This method is used to retrieve a product variant by its ID.
Example
A simple example that retrieves a product variant by its ID:
To specify relations that should be retrieved:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductVariant (id: string) {
const productModule = await initializeProductModule()
const variant = await productModule.retrieveVariant(id, {
relations: ["options"]
})
// do something with the product variant or return it
}
Parameters
productVariantId
stringRequiredThe ID of the product variant to retrieve.
config
FindConfig<ProductVariantDTO>The configurations determining how the product variant is retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a product variant.
config
FindConfig<ProductVariantDTO>select
or relations
, accept the
attributes or relations associated with a product variant.sharedContext
ContextA context used to share resources, such as transaction manager, between the application and the module.
sharedContext
ContextReturns
The retrieved product variant.
Was this section helpful?