Skip to main content
Skip to main content

CollectionsResource

This class is used to send requests to Store Product Collection API Routes. All its method are available in the JS Client under the medusa.collections property.

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. Using the methods in this class, you can list or retrieve a collection's details and products.

Methods

list

Retrieve a list of product collections. The product collections can be filtered by fields such as handle or created_at passed in the query parameter. The product collections can also be paginated.

Example

To list product collections:

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
medusa.collections.list()
.then(({ collections, limit, offset, count }) => {
console.log(collections.length);
})

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 })
medusa.collections.list({
limit,
offset
})
.then(({ collections, limit, offset, count }) => {
console.log(collections.length);
})

Parameters

Filters and pagination configurations to apply on the retrieved product collections.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<StoreCollectionsListRes>Required
Resolves to the list of product collections with pagination fields.

retrieve

Retrieve a product collection's details.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
medusa.collections.retrieve(collectionId)
.then(({ collection }) => {
console.log(collection.id);
})

Parameters

idstringRequired
The ID of the product collection.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<StoreCollectionsRes>Required
Resolves to the collection's details.
Was this section helpful?