--- displayed_sidebar: jsClientSidebar slug: /references/js-client/AdminCustomerGroupsResource --- import ParameterTypes from "@site/src/components/ParameterTypes" # AdminCustomerGroupsResource This class is used to send requests to [Admin Customer Group API Routes](https://docs.medusajs.com/api/admin#customer-groups). All its method are available in the JS Client under the `medusa.admin.customerGroups` property. All methods in this class require [user authentication](AdminAuthResource.mdx#createsession). Customer Groups can be used to organize customers that share similar data or attributes into dedicated groups. This can be useful for different purposes such as setting a different price for a specific customer group. Related Guide: [How to manage customer groups](https://docs.medusajs.com/modules/customers/admin/manage-customer-groups). ## Methods ### addCustomers Add a list of customers to a customer group. #### 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": "name", "type": "`string`", "description": "The name of the customer group", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "price_lists", "type": "[PriceList](../internal/classes/internal.PriceList.mdx)[]", "description": "The price lists that are associated with the customer group.", "optional": false, "defaultValue": "", "expandable": true, "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 customer group. #### 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.customerGroups .create({ name: "VIP", }) .then(({ customer_group }) => { console.log(customer_group.id) }) ``` #### Parameters `", "description": "Metadata of the customer group.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "name", "type": "`string`", "description": "Name of the customer group", "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": "name", "type": "`string`", "description": "The name of the customer group", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "price_lists", "type": "[PriceList](../internal/classes/internal.PriceList.mdx)[]", "description": "The price lists that are associated with the customer group.", "optional": false, "defaultValue": "", "expandable": true, "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 customer group. This doesn't delete the customers associated with the customer group. #### 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.customerGroups .delete(customerGroupId) .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 customer groups. The customer groups can be filtered by fields such as `name` or `id`. The customer groups can also be sorted or paginated. #### Example To list customer groups: ```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.customerGroups .list() .then(({ customer_groups, limit, offset, count }) => { console.log(customer_groups.length) }) ``` To specify relations that should be retrieved within the customer groups: ```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.customerGroups .list({ expand: "customers", }) .then(({ customer_groups, limit, offset, count }) => { console.log(customer_groups.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.customerGroups .list({ expand: "customers", limit, offset, }) .then(({ customer_groups, limit, offset, count }) => { console.log(customer_groups.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": "name", "type": "`string`", "description": "The name of the customer group", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "price_lists", "type": "[PriceList](../internal/classes/internal.PriceList.mdx)[]", "description": "The price lists that are associated with the customer group.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### listCustomers Retrieve a list of customers in a customer group. The customers can be filtered by the `q` field. The customers can also be paginated. #### 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.customerGroups .listCustomers(customerGroupId) .then(({ customers }) => { console.log(customers.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": "orders", "type": "[Order](../internal/classes/internal.Order.mdx)[]", "description": "The details of the orders this customer placed.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "phone", "type": "`string`", "description": "The customer's phone number", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "shipping_addresses", "type": "[Address](../internal/classes/internal.Address.mdx)[]", "description": "The details of the shipping addresses associated with the customer.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### removeCustomers Remove a list of customers from a customer group. This doesn't delete the customer, only the association between the customer and the customer group. #### 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.customerGroups .removeCustomers(customerGroupId, { customer_ids: [ { id: customerId, }, ], }) .then(({ customer_group }) => { console.log(customer_group.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": "name", "type": "`string`", "description": "The name of the customer group", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "price_lists", "type": "[PriceList](../internal/classes/internal.PriceList.mdx)[]", "description": "The price lists that are associated with the customer group.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### retrieve Retrieve a customer group by its ID. You can expand the customer group's relations or select the fields that should be returned. #### 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.customerGroups .retrieve(customerGroupId) .then(({ customer_group }) => { console.log(customer_group.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": "name", "type": "`string`", "description": "The name of the customer group", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "price_lists", "type": "[PriceList](../internal/classes/internal.PriceList.mdx)[]", "description": "The price lists that are associated with the customer group.", "optional": false, "defaultValue": "", "expandable": true, "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 customer group's details. #### Parameters `", "description": "Metadata of the customer group.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "name", "type": "`string`", "description": "Name of the customer group", "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": "name", "type": "`string`", "description": "The name of the customer group", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "price_lists", "type": "[PriceList](../internal/classes/internal.PriceList.mdx)[]", "description": "The price lists that are associated with the customer group.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} />