AdminCustomerGroupsResource
This class is used to send requests to Admin Customer Group API Routes. All its method
are available in the JS Client under the medusa.admin.customerGroups
property.
All methods in this class require user authentication.
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.
Methods
addCustomers
Add a list of customers to a customer group.
Parameters
id
stringRequiredThe customers to add to the customer group.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCustomerGroupsRes>RequiredResolves to the customer group's details.
ResponsePromise
ResponsePromise<AdminCustomerGroupsRes>Requiredcreate
Create a customer group.
Example
Parameters
The data of the customer group to create.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCustomerGroupsRes>RequiredResolves to the customer group's details.
ResponsePromise
ResponsePromise<AdminCustomerGroupsRes>Requireddelete
Delete a customer group. This doesn't delete the customers associated with the customer group.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<DeleteResponse>RequiredResolves to the deletion operation details.
ResponsePromise
ResponsePromise<DeleteResponse>Requiredlist
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:
To specify relations that should be retrieved within the customer groups:
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:
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
Filters and pagination configurations to apply on the retrieved customer groups.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCustomerGroupsListRes>RequiredResolves to the list of customer groups with pagination fields.
ResponsePromise
ResponsePromise<AdminCustomerGroupsListRes>RequiredlistCustomers
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
Parameters
id
stringRequiredFilters and pagination configurations to apply on the retrieved customers.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCustomersListRes>RequiredResolves to the list of customers with pagination fields.
ResponsePromise
ResponsePromise<AdminCustomersListRes>RequiredremoveCustomers
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
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
id
stringRequiredThe customers to remove from the customer group.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCustomerGroupsRes>RequiredResolves to the customer group's details.
ResponsePromise
ResponsePromise<AdminCustomerGroupsRes>Requiredretrieve
Retrieve a customer group by its ID. You can expand the customer group's relations or select the fields that should be returned.
Example
Parameters
id
stringRequiredConfigurations to apply on the retrieved customer group.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCustomerGroupsRes>RequiredResolves to the customer group's details.
ResponsePromise
ResponsePromise<AdminCustomerGroupsRes>Requiredupdate
Update a customer group's details.
Parameters
id
stringRequiredThe attributes to update in the customer group.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCustomerGroupsRes>RequiredResolves to the customer group's details.
ResponsePromise
ResponsePromise<AdminCustomerGroupsRes>Required