--- 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 ", "optional": false, "defaultValue": "", "description": "Resolves to the customer group's details.", "expandable": false, "children": [ { "name": "AdminCustomerGroupsRes", "type": "`object`", "description": "The customer group's details.", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "customer_group", "type": "[`CustomerGroup`](../internal/classes/internal.CustomerGroup.mdx)", "description": "Customer group details.", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "created_at", "type": "`Date`", "description": "The date with timezone at which the resource was created.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "customers", "type": "[`Customer`](../internal/classes/internal.Customer.mdx)[]", "description": "The details of the customers that belong to the customer group.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "deleted_at", "type": "``null`` \\| `Date`", "description": "The date with timezone at which the resource was deleted.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The customer group's ID", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "metadata", "type": "Record<`string`, `unknown`\\>", "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<`string`, `any`\\>", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns ", "optional": false, "defaultValue": "", "description": "Resolves to the customer group's details.", "expandable": false, "children": [ { "name": "AdminCustomerGroupsRes", "type": "`object`", "description": "The customer group's details.", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "customer_group", "type": "[`CustomerGroup`](../internal/classes/internal.CustomerGroup.mdx)", "description": "Customer group details.", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "created_at", "type": "`Date`", "description": "The date with timezone at which the resource was created.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "customers", "type": "[`Customer`](../internal/classes/internal.Customer.mdx)[]", "description": "The details of the customers that belong to the customer group.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "deleted_at", "type": "``null`` \\| `Date`", "description": "The date with timezone at which the resource was deleted.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The customer group's ID", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "metadata", "type": "Record<`string`, `unknown`\\>", "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 ", "optional": false, "defaultValue": "", "description": "Resolves to the deletion operation details.", "expandable": false, "children": [ { "name": "deleted", "type": "`boolean`", "description": "Whether the item was deleted successfully.", "optional": false, "defaultValue": "true", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The ID of the deleted item.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "object", "type": "`string`", "description": "The type of the deleted item.", "optional": false, "defaultValue": "product-collection", "expandable": false, "children": [] } ] } ]} /> ___ ### 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 ", "optional": false, "defaultValue": "", "description": "Resolves to the list of customer groups with pagination fields.", "expandable": false, "children": [ { "name": "AdminCustomerGroupsListRes", "type": "[`PaginatedResponse`](../internal/interfaces/internal.PaginatedResponse.mdx) & { `customer_groups`: [`CustomerGroup`](../internal/classes/internal.CustomerGroup.mdx)[] }", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "count", "type": "`number`", "description": "The total number of items available.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "limit", "type": "`number`", "description": "The maximum number of items that can be returned in the list.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "offset", "type": "`number`", "description": "The number of items skipped before the returned items in the list.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "customer_groups", "type": "[`CustomerGroup`](../internal/classes/internal.CustomerGroup.mdx)[]", "description": "An array of customer group details.", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "created_at", "type": "`Date`", "description": "The date with timezone at which the resource was created.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "customers", "type": "[`Customer`](../internal/classes/internal.Customer.mdx)[]", "description": "The details of the customers that belong to the customer group.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "deleted_at", "type": "``null`` \\| `Date`", "description": "The date with timezone at which the resource was deleted.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The customer group's ID", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "metadata", "type": "Record<`string`, `unknown`\\>", "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 ", "optional": false, "defaultValue": "", "description": "Resolves to the list of customers with pagination fields.", "expandable": false, "children": [ { "name": "AdminCustomersListRes", "type": "[`PaginatedResponse`](../internal/interfaces/internal.PaginatedResponse.mdx) & { `customers`: [`Customer`](../internal/classes/internal.Customer.mdx)[] }", "description": "The list of customers with pagination fields.", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "count", "type": "`number`", "description": "The total number of items available.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "limit", "type": "`number`", "description": "The maximum number of items that can be returned in the list.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "offset", "type": "`number`", "description": "The number of items skipped before the returned items in the list.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "customers", "type": "[`Customer`](../internal/classes/internal.Customer.mdx)[]", "description": "An array of customer details.", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "billing_address", "type": "[`Address`](../internal/classes/internal.Address.mdx)", "description": "The details of the billing address associated with the customer.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "billing_address_id", "type": "``null`` \\| `string`", "description": "The customer's billing address ID", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "created_at", "type": "`Date`", "description": "The date with timezone at which the resource was created.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "deleted_at", "type": "``null`` \\| `Date`", "description": "The date with timezone at which the resource was deleted.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "email", "type": "`string`", "description": "The customer's email", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "first_name", "type": "`string`", "description": "The customer's first name", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "groups", "type": "[`CustomerGroup`](../internal/classes/internal.CustomerGroup.mdx)[]", "description": "The customer groups the customer belongs to.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "has_account", "type": "`boolean`", "description": "Whether the customer has an account or not", "optional": false, "defaultValue": "false", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The customer's ID", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "last_name", "type": "`string`", "description": "The customer's last name", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "metadata", "type": "Record<`string`, `unknown`\\>", "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 ", "optional": false, "defaultValue": "", "description": "Resolves to the customer group's details.", "expandable": false, "children": [ { "name": "AdminCustomerGroupsRes", "type": "`object`", "description": "The customer group's details.", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "customer_group", "type": "[`CustomerGroup`](../internal/classes/internal.CustomerGroup.mdx)", "description": "Customer group details.", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "created_at", "type": "`Date`", "description": "The date with timezone at which the resource was created.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "customers", "type": "[`Customer`](../internal/classes/internal.Customer.mdx)[]", "description": "The details of the customers that belong to the customer group.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "deleted_at", "type": "``null`` \\| `Date`", "description": "The date with timezone at which the resource was deleted.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The customer group's ID", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "metadata", "type": "Record<`string`, `unknown`\\>", "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 ", "optional": false, "defaultValue": "", "description": "Resolves to the customer group's details.", "expandable": false, "children": [ { "name": "AdminCustomerGroupsRes", "type": "`object`", "description": "The customer group's details.", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "customer_group", "type": "[`CustomerGroup`](../internal/classes/internal.CustomerGroup.mdx)", "description": "Customer group details.", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "created_at", "type": "`Date`", "description": "The date with timezone at which the resource was created.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "customers", "type": "[`Customer`](../internal/classes/internal.Customer.mdx)[]", "description": "The details of the customers that belong to the customer group.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "deleted_at", "type": "``null`` \\| `Date`", "description": "The date with timezone at which the resource was deleted.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The customer group's ID", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "metadata", "type": "Record<`string`, `unknown`\\>", "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<`string`, `any`\\>", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns ", "optional": false, "defaultValue": "", "description": "Resolves to the customer group's details.", "expandable": false, "children": [ { "name": "AdminCustomerGroupsRes", "type": "`object`", "description": "The customer group's details.", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "customer_group", "type": "[`CustomerGroup`](../internal/classes/internal.CustomerGroup.mdx)", "description": "Customer group details.", "optional": false, "defaultValue": "", "expandable": false, "children": [ { "name": "created_at", "type": "`Date`", "description": "The date with timezone at which the resource was created.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "customers", "type": "[`Customer`](../internal/classes/internal.Customer.mdx)[]", "description": "The details of the customers that belong to the customer group.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "deleted_at", "type": "``null`` \\| `Date`", "description": "The date with timezone at which the resource was deleted.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The customer group's ID", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "metadata", "type": "Record<`string`, `unknown`\\>", "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": [] } ] } ] } ] } ]} />