AdminCustomersResource
This class is used to send requests to Admin Customer API Routes. All its method
are available in the JS Client under the medusa.admin.customers
property.
All methods in this class require user authentication.
Customers can either be created when they register through the CustomersResource.create method, or created by the admin using the create method.
Related Guide: How to manage customers.
Methods
create
Create a customer as an admin.
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.customers.create({
email: "user@example.com",
first_name: "Caterina",
last_name: "Yost",
password: "supersecret"
})
.then(({ customer }) => {
console.log(customer.id);
})
Parameters
The customer to create.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCustomersRes>RequiredResolves to the customer's details.
ResponsePromise
ResponsePromise<AdminCustomersRes>Requiredlist
Retrieve a list of Customers. The customers can be filtered by fields such as q
or groups
. The customers can also be paginated.
Example
To list customers:
To specify relations that should be retrieved within the customers:
By default, only the first 50
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.customers.list({
expand: "billing_address",
limit,
offset
})
.then(({ customers, limit, offset, count }) => {
console.log(customers.length);
})
Parameters
Filters 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>Requiredretrieve
Retrieve the details of a customer.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCustomersRes>RequiredResolves to the customer's details.
ResponsePromise
ResponsePromise<AdminCustomersRes>Requiredupdate
Update a customer's details.
Example
Parameters
id
stringRequiredThe attributes to update in the customer.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminCustomersRes>RequiredResolves to the customer's details.
ResponsePromise
ResponsePromise<AdminCustomersRes>Required