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
create
Create a customer group.
Example
Parameters
The data of the customer group to create.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminCustomerGroupsRes>RequiredResolves to the customer group's details.
ResponsePromiseResponsePromise<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
idstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Configurations to apply on the retrieved customer group.
Returns
ResponsePromiseResponsePromise<AdminCustomerGroupsRes>RequiredResolves to the customer group's details.
ResponsePromiseResponsePromise<AdminCustomerGroupsRes>Requiredupdate
Update a customer group's details.
Parameters
idstringRequiredThe attributes to update in the customer group.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminCustomerGroupsRes>RequiredResolves to the customer group's details.
ResponsePromiseResponsePromise<AdminCustomerGroupsRes>Requireddelete
Delete a customer group. This doesn't delete the customers associated with the customer group.
Example
Parameters
idstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<DeleteResponse>RequiredResolves to the deletion operation details.
ResponsePromiseResponsePromise<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
customHeadersRecord<string, any>RequiredDefault: {}
Filters and pagination configurations to apply on the retrieved customer groups.
Returns
ResponsePromiseResponsePromise<AdminCustomerGroupsListRes>RequiredResolves to the list of customer groups with pagination fields.
ResponsePromiseResponsePromise<AdminCustomerGroupsListRes>RequiredaddCustomers
Add a list of customers to a customer group.
Parameters
idstringRequiredThe customers to add to the customer group.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminCustomerGroupsRes>RequiredResolves to the customer group's details.
ResponsePromiseResponsePromise<AdminCustomerGroupsRes>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
idstringRequiredThe customers to remove from the customer group.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminCustomerGroupsRes>RequiredResolves to the customer group's details.
ResponsePromiseResponsePromise<AdminCustomerGroupsRes>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
idstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Filters and pagination configurations to apply on the retrieved customers.
Returns
ResponsePromiseResponsePromise<AdminCustomersListRes>RequiredResolves to the list of customers with pagination fields.
ResponsePromiseResponsePromise<AdminCustomersListRes>Required