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 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
create
Create a product collection.
Example
Parameters
The data of the product collection to create.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminCollectionsRes>RequiredResolves to the created product collection's details.
ResponsePromiseResponsePromise<AdminCollectionsRes>Requiredupdate
Update a product collection's details.
Example
Parameters
idstringRequiredThe data to update in the product collection.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminCollectionsRes>RequiredResolves to the product collection's details.
ResponsePromiseResponsePromise<AdminCollectionsRes>Requireddelete
Delete a product collection. This does not delete associated products.
Example
Parameters
idstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<DeleteResponse>RequiredResolves to the deletion operation details.
ResponsePromiseResponsePromise<DeleteResponse>Requiredretrieve
Retrieve a product collection by its ID. The products associated with it are expanded and returned as well.
Example
Parameters
idstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminCollectionsRes>RequiredResolves to the product collection's details.
ResponsePromiseResponsePromise<AdminCollectionsRes>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
customHeadersRecord<string, any>RequiredDefault: {}
Filters and pagination configurations to apply on the retrieved product collections.
Returns
ResponsePromiseResponsePromise<AdminCollectionsListRes>RequiredResolves to the list of product collections with pagination fields.
ResponsePromiseResponsePromise<AdminCollectionsListRes>RequiredaddProducts
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
idstringRequiredThe products to add.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminCollectionsRes>RequiredResolves to the product collection's details.
ResponsePromiseResponsePromise<AdminCollectionsRes>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
idstringRequiredThe products to remove from the collection.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminDeleteProductsFromCollectionRes>RequiredResolves to the deletion operation details.
ResponsePromiseResponsePromise<AdminDeleteProductsFromCollectionRes>Required