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 user 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
customHeadersRecord<string, any>RequiredDefault: {}
Filters and pagination configurations to apply on the retrieved product variants.
Returns
ResponsePromiseResponsePromise<AdminVariantsListRes>RequiredResolves to the list of product variants with pagination fields.
ResponsePromiseResponsePromise<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
idstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Configurations to apply on the retrieved product variant.
Returns
ResponsePromiseResponsePromise<AdminVariantsRes>RequiredResolves to the product variant's details.
ResponsePromiseResponsePromise<AdminVariantsRes>RequiredgetInventory
Retrieve the available inventory of a product variant.
Example
Parameters
variantIdstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminGetVariantsVariantInventoryRes>RequiredResolves to the inventory details of the product variant.
ResponsePromiseResponsePromise<AdminGetVariantsVariantInventoryRes>Required