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.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the customer's details.
list
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:
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",
})
.then(({ customers, limit, offset, count }) => {
console.log(customers.length)
})
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.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the list of customers with pagination fields.
retrieve
Retrieve the details of a customer.
Example
Parameters
idstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the customer's details.
update
Update a customer's details.
Example
Parameters
idstringRequiredThe attributes to update in the customer.
customHeadersRecord<string, any>RequiredDefault: {}