AdminPriceListResource
This class is used to send requests to Admin Price List API Routes. All its method
are available in the JS Client under the medusa.admin.priceLists
property.
All methods in this class require user authentication.
A price list are special prices applied to products based on a set of conditions, such as customer group.
Related Guide: How to manage price lists.
Methods
create
Create a price list.
Example
Parameters
The price list to create.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPriceListRes>RequiredResolves to the price list details.
ResponsePromise
ResponsePromise<AdminPriceListRes>Requiredupdate
Update a price list's details.
Example
Parameters
id
stringRequiredThe attributes to update in the price list.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPriceListRes>RequiredResolves to the price list details.
ResponsePromise
ResponsePromise<AdminPriceListRes>Requireddelete
Delete a price list and its associated prices.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<DeleteResponse>RequiredResolves to the deletion operation's details.
ResponsePromise
ResponsePromise<DeleteResponse>Requiredretrieve
Retrieve a price list's details.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPriceListRes>RequiredResolves to the price list details.
ResponsePromise
ResponsePromise<AdminPriceListRes>Requiredlist
Retrieve a list of price lists. The price lists can be filtered by fields such as q
or status
passed in the query
parameter. The price lists can also be sorted or paginated.
Example
To list price lists:
To specify relations that should be retrieved within the price lists:
By default, only the first 10
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.priceLists.list({
expand: "prices",
limit,
offset
})
.then(({ price_lists, limit, offset, count }) => {
console.log(price_lists.length);
})
Parameters
customHeaders
Record<string, any>RequiredDefault: {}
Filters and pagination configurations to apply on the retrieved price lists.
Returns
ResponsePromise
ResponsePromise<AdminPriceListsListRes>RequiredResolves to the list of price lists with pagination fields.
ResponsePromise
ResponsePromise<AdminPriceListsListRes>RequiredlistProducts
Retrieve a price list's 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 in a price list:
To specify relations that should be retrieved within the products:
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.priceLists.listProducts(priceListId, {
expand: "variants"
})
.then(({ products, limit, offset, count }) => {
console.log(products.length);
})
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.priceLists.listProducts(priceListId, {
expand: "variants",
limit,
offset
})
.then(({ products, limit, offset, count }) => {
console.log(products.length);
})
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Filters and pagination configurations applied on the retrieved products.
Returns
ResponsePromise
ResponsePromise<AdminPriceListsProductsListRes>RequiredResolves to the list of products with pagination fields.
ResponsePromise
ResponsePromise<AdminPriceListsProductsListRes>RequiredaddPrices
Add or update a list of prices in a price list.
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.priceLists.addPrices(priceListId, {
prices: [
{
amount: 1000,
variant_id,
currency_code: "eur"
}
]
})
.then(({ price_list }) => {
console.log(price_list.id);
})
Parameters
id
stringRequiredThe details of prices to add or update.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPriceListRes>RequiredResolves to the price list's details.
ResponsePromise
ResponsePromise<AdminPriceListRes>RequireddeletePrices
Delete a list of prices in a price list
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.priceLists.deletePrices(priceListId, {
price_ids: [
price_id
]
})
.then(({ ids, object, deleted }) => {
console.log(ids.length);
})
Parameters
id
stringRequiredThe prices to delete.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPriceListDeleteBatchRes>RequiredResolves to the deletion operation's details.
ResponsePromise
ResponsePromise<AdminPriceListDeleteBatchRes>RequireddeleteProductPrices
Delete all the prices related to a specific product in a price list.
Example
Parameters
priceListId
stringRequiredproductId
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPriceListDeleteBatchRes>RequiredResolves to the deletion operation's details.
ResponsePromise
ResponsePromise<AdminPriceListDeleteBatchRes>RequireddeleteVariantPrices
Delete all the prices related to a specific product variant in a price list.
Example
Parameters
priceListId
stringRequiredvariantId
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPriceListDeleteBatchRes>RequiredResolves to the deletion operation's details.
ResponsePromise
ResponsePromise<AdminPriceListDeleteBatchRes>RequireddeleteProductsPrices
Delete all the prices associated with multiple products in a price list.
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.priceLists.deleteProductsPrices(priceListId, {
product_ids: [
productId1,
productId2,
]
})
.then(({ ids, object, deleted }) => {
console.log(ids.length);
})
Parameters
priceListId
stringRequiredThe products whose prices should be deleted.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPriceListDeleteBatchRes>RequiredResolves to the deletion operation's details.
ResponsePromise
ResponsePromise<AdminPriceListDeleteBatchRes>Required