--- displayed_sidebar: jsClientSidebar slug: /references/js-client/AdminCollectionsResource --- import ParameterTypes from "@site/src/components/ParameterTypes" # AdminCollectionsResource This class is used to send requests to [Admin Product Collection API Routes](https://docs.medusajs.com/api/admin#product-collections). All its method are available in the JS Client under the `medusa.admin.collections` property. All methods in this class require [user authentication](AdminAuthResource.mdx#createsession). 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 ```ts 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 `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "products", "type": "[Product](../internal/classes/internal.Product.mdx)[]", "description": "The details of the products that belong to this product collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "title", "type": "`string`", "description": "The title that the Product Collection is identified by.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### create Create a product collection. #### Example ```ts 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 .create({ title: "New Collection", }) .then(({ collection }) => { console.log(collection.id) }) ``` #### Parameters `", "description": "An optional set of key-value pairs to hold additional information.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "title", "type": "`string`", "description": "The title of the collection.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] }, { "name": "customHeaders", "type": "`Record`", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "products", "type": "[Product](../internal/classes/internal.Product.mdx)[]", "description": "The details of the products that belong to this product collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "title", "type": "`string`", "description": "The title that the Product Collection is identified by.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### delete Delete a product collection. This does not delete associated products. #### Example ```ts 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 .delete(collectionId) .then(({ id, object, deleted }) => { console.log(id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns ___ ### list 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: ```ts 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 .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: ```ts 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 .list({ limit, offset, }) .then(({ collections, limit, offset, count }) => { console.log(collections.length) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "products", "type": "[Product](../internal/classes/internal.Product.mdx)[]", "description": "The details of the products that belong to this product collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "title", "type": "`string`", "description": "The title that the Product Collection is identified by.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### removeProducts Remove a list of products from a collection. This would not delete the product, only the association between the product and the collection. #### Example ```ts 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 `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns ___ ### retrieve Retrieve a product collection by its ID. The products associated with it are expanded and returned as well. #### Example ```ts 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.retrieve(collectionId).then(({ collection }) => { console.log(collection.id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "products", "type": "[Product](../internal/classes/internal.Product.mdx)[]", "description": "The details of the products that belong to this product collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "title", "type": "`string`", "description": "The title that the Product Collection is identified by.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### update Update a product collection's details. #### Example ```ts 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 .update(collectionId, { title: "New Collection", }) .then(({ collection }) => { console.log(collection.id) }) ``` #### Parameters `", "description": "An optional set of key-value pairs to hold additional information.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "title", "type": "`string`", "description": "The title of the collection.", "optional": true, "defaultValue": "", "expandable": false, "children": [] } ] }, { "name": "customHeaders", "type": "`Record`", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "products", "type": "[Product](../internal/classes/internal.Product.mdx)[]", "description": "The details of the products that belong to this product collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "title", "type": "`string`", "description": "The title that the Product Collection is identified by.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} />