AdminVariantsResource
This class is used to send requests to Admin Product Variant API Routes. All its method
are available in the JS Client under the medusa.admin.variants
property.
All methods in this class require authentication.
Product variants are the actual salable item in your store. Each variant is a combination of the different option values available on the product. Product variants can be managed through AdminProductsResource.
Related Guide: How to manage product variants.
Methods
list
Retrieve a list of product variants. The product variant can be filtered by fields such as id
or title
passed in the query
parameter. The product variant can also be paginated.
Example
To list product variants:
To specify relations that should be retrieved within the product variants:
By default, only the first 100
records are retrieved. You can control pagination by specifying the limit
and offset
properties:
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.variants.list({
expand: "options",
limit,
offset
})
.then(({ variants, limit, offset, count }) => {
console.log(variants.length);
})
Parameters
customHeaders
Record<string, any>RequiredDefault: {}
Filters and pagination configurations to apply on the retrieved product variants.
Returns
ResponsePromise
ResponsePromise<AdminVariantsListRes>RequiredResolves to the list of product variants with pagination fields.
ResponsePromise
ResponsePromise<AdminVariantsListRes>Requiredretrieve
Retrieve a product variant's details.
Example
A simple example that retrieves a product variant by its ID:
To specify relations that should be retrieved:
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Configurations to apply on the retrieved product variant.
Returns
ResponsePromise
ResponsePromise<AdminVariantsRes>RequiredResolves to the product variant's details.
ResponsePromise
ResponsePromise<AdminVariantsRes>RequiredgetInventory
Retrieve the available inventory of a product variant.
Example
Parameters
variantId
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminGetVariantsVariantInventoryRes>RequiredResolves to the inventory details of the product variant.
ResponsePromise
ResponsePromise<AdminGetVariantsVariantInventoryRes>Required