AdminCollectionsResource
This class is used to send requests to Admin Product Collection API Routes. All its method
are available in the JS Client under the medusa.admin.collections
property.
All methods in this class require user authentication.
A product collection is used to organize products for different purposes such as marketing or discount purposes. For example, you can create a Summer Collection.
Methods
addProducts
Add products to collection.
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.collections.addProducts(collectionId, {
product_ids: [
productId1,
productId2
]
})
.then(({ collection }) => {
console.log(collection.products)
})
Parameters
id
stringRequiredThe products to add.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCollectionsRes>RequiredResolves to the product collection's details.
ResponsePromise
ResponsePromise<AdminCollectionsRes>Requiredcreate
Create a product collection.
Example
Parameters
The data of the product collection to create.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCollectionsRes>RequiredResolves to the created product collection's details.
ResponsePromise
ResponsePromise<AdminCollectionsRes>Requireddelete
Delete a product collection. This does not delete associated products.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<DeleteResponse>RequiredResolves to the deletion operation details.
ResponsePromise
ResponsePromise<DeleteResponse>Requiredlist
Retrieve a list of product collections. The product collections can be filtered by fields such as handle
or title
. The collections can also be sorted or paginated.
Example
To list product collections:
By default, only the first 10
records are retrieved. You can control pagination by specifying the limit
and offset
properties:
Parameters
Filters and pagination configurations to apply on the retrieved product collections.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCollectionsListRes>RequiredResolves to the list of product collections with pagination fields.
ResponsePromise
ResponsePromise<AdminCollectionsListRes>RequiredremoveProducts
Remove a list of products from a collection. This would not delete the product, only the association between the product and the collection.
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.collections.removeProducts(collectionId, {
product_ids: [
productId1,
productId2
]
})
.then(({ id, object, removed_products }) => {
console.log(removed_products)
})
Parameters
id
stringRequiredThe products to remove from the collection.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminDeleteProductsFromCollectionRes>RequiredResolves to the deletion operation details.
ResponsePromise
ResponsePromise<AdminDeleteProductsFromCollectionRes>Requiredretrieve
Retrieve a product collection by its ID. The products associated with it are expanded and returned as well.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCollectionsRes>RequiredResolves to the product collection's details.
ResponsePromise
ResponsePromise<AdminCollectionsRes>Requiredupdate
Update a product collection's details.
Example
Parameters
id
stringRequiredThe data to update in the product collection.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCollectionsRes>RequiredResolves to the product collection's details.
ResponsePromise
ResponsePromise<AdminCollectionsRes>Required