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 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.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminCustomersRes>RequiredResolves to the customer's details.
ResponsePromiseResponsePromise<AdminCustomersRes>Requiredupdate
Update a customer's details.
Example
Parameters
idstringRequiredThe attributes to update in the customer.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminCustomersRes>RequiredResolves to the customer's details.
ResponsePromiseResponsePromise<AdminCustomersRes>Requiredretrieve
Retrieve the details of a customer.
Example
Parameters
idstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
ResponsePromiseResponsePromise<AdminCustomersRes>RequiredResolves to the customer's details.
ResponsePromiseResponsePromise<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
customHeadersRecord<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