AdminProductsResource
This class is used to send requests to Admin Product API Routes. All its method
are available in the JS Client under the medusa.admin.products
property.
All methods in this class require user authentication.
Products are saleable items in a store. This also includes saleable gift cards in a store.
Related Guide: How to manage products.
Methods
addOption
Add a product option to a product.
Example
Parameters
id
stringRequiredThe option to add.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminProductsRes>RequiredResolves to the product's details. You can access the variant under the options
property.
ResponsePromise
ResponsePromise<AdminProductsRes>Requiredoptions
property.create
Create a new Product. This API Route can also be used to create a gift card if the is_giftcard
field is set to true
.
Example
Parameters
The product to create.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminProductsRes>RequiredResolves to the product's details.
ResponsePromise
ResponsePromise<AdminProductsRes>RequiredcreateVariant
Create a product variant associated with a product. Each product variant must have a unique combination of product option values.
Example
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.products.createVariant(productId, {
title: "Color",
prices: [
{
amount: 1000,
currency_code: "eur"
}
],
options: [
{
option_id,
value: "S"
}
],
inventory_quantity: 100
})
.then(({ product }) => {
console.log(product.id);
})
Parameters
id
stringRequiredThe product variant to create.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminProductsRes>RequiredResolves to the product's details. You can access the variant under the variants
property.
ResponsePromise
ResponsePromise<AdminProductsRes>Requiredvariants
property.delete
Delete a product and its associated product variants and options.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminProductsDeleteRes>RequiredResolves to the deletion operation's details.
ResponsePromise
ResponsePromise<AdminProductsDeleteRes>RequireddeleteOption
Delete a product option. If there are product variants that use this product option, they must be deleted before deleting the product option.
Parameters
id
stringRequiredoptionId
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminProductsDeleteOptionRes>RequiredResolves to the deletion operation's details.
ResponsePromise
ResponsePromise<AdminProductsDeleteOptionRes>RequireddeleteVariant
Delete a product variant.
Example
Parameters
id
stringRequiredvariantId
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminProductsDeleteVariantRes>RequiredResolves to the deletion operation's details.
ResponsePromise
ResponsePromise<AdminProductsDeleteVariantRes>Requiredlist
Retrieve a list of products. The products can be filtered by fields such as q
or status
passed in the query
parameter. The products can also be sorted or paginated.
Example
To list products:
To specify relations that should be retrieved within the products:
By default, only the first 50
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.products.list({
expand: "images",
limit,
offset
})
.then(({ products, limit, offset, count }) => {
console.log(products.length);
})
Parameters
Filters and pagination configurations to apply on the retrieved products.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminProductsListRes>RequiredResolves to the list of products with pagination fields.
ResponsePromise
ResponsePromise<AdminProductsListRes>RequiredlistTags
Retrieve a list of Product Tags with how many times each is used in products.
Example
Parameters
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminProductsListTagsRes>RequiredResolves to the list of tags.
ResponsePromise
ResponsePromise<AdminProductsListTagsRes>Requiredretrieve
Retrieve a product's details.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminProductsRes>RequiredResolves to the product's details.
ResponsePromise
ResponsePromise<AdminProductsRes>RequiredsetMetadata
Set the metadata of a product. It can be any key-value pair, which allows adding custom data to a product. Learn about how you can update and delete the metadata attribute here.
Example
Parameters
id
stringRequiredThe metadata details to add, update, or delete.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminProductsRes>RequiredResolves to the product's details.
ResponsePromise
ResponsePromise<AdminProductsRes>Requiredupdate
Update a Product's details.
Example
Parameters
id
stringRequiredThe attributes to update in a product.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminProductsRes>RequiredResolves to the product's details.
ResponsePromise
ResponsePromise<AdminProductsRes>RequiredupdateOption
Update a product option's details.
Example
Parameters
id
stringRequiredoptionId
stringRequiredThe attributes to update in the product option.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminProductsRes>RequiredResolves to the product's details. You can access the variant under the options
property.
ResponsePromise
ResponsePromise<AdminProductsRes>Requiredoptions
property.updateVariant
Update a product variant's details.
Example
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.products.updateVariant(productId, variantId, {
title: "Color",
prices: [
{
amount: 1000,
currency_code: "eur"
}
],
options: [
{
option_id,
value: "S"
}
],
inventory_quantity: 100
})
.then(({ product }) => {
console.log(product.id);
})
Parameters
id
stringRequiredvariantId
stringRequiredThe attributes to update in the product variant.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminProductsRes>RequiredResolves to the product's details. You can access the variant under the variants
property.
ResponsePromise
ResponsePromise<AdminProductsRes>Requiredvariants
property.