customer - JS SDK Admin Reference

This documentation provides a reference to the sdk.admin.customer set of methods used to send requests to Medusa's Admin API routes.

create#

This method creates a customer. It sends a request to the Create Customer API route.

Example#

Code
1sdk.admin.customer.create({2  email: "customer@gmail.com"3})4.then(({ customer }) => {5  console.log(customer)6})

Parameters#

The customer's details.
querySelectParamsOptional
Configure the fields to retrieve in the customer.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

PromisePromise<AdminCustomerResponse>
The customer's details.

update#

This method updates a customer's details. It sends a request to the Update Customer API route.

Example#

Code
1sdk.admin.customer.update("cus_123", {2  first_name: "John"3})4.then(({ customer }) => {5  console.log(customer)6})

Parameters#

idstring
The customer's ID.
The details to update of the customer.
querySelectParamsOptional
Configure the fields to retrieve in the customer.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

PromisePromise<AdminCustomerResponse>
The customer's details.

list#

This method retrieves a paginated list of customers. It sends a request to the List Customers API route.

Example#

To retrieve the list of customers:

Code
1sdk.admin.customer.list()2.then(({ customers, count, limit, offset }) => {3  console.log(customers)4})

To configure the pagination, pass the limit and offset query parameters.

For example, to retrieve only 10 items and skip 10 items:

Code
1sdk.admin.customer.list({2  limit: 10,3  offset: 104})5.then(({ customers, count, limit, offset }) => {6  console.log(customers)7})

Using the fields query parameter, you can specify the fields and relations to retrieve in each customer:

Code
1sdk.admin.customer.list({2  fields: "id,*groups"3})4.then(({ customers, count, limit, offset }) => {5  console.log(customers)6})

Learn more about the fields property in the API reference.

Parameters#

queryParamsAdminCustomerFiltersOptional
Filters and pagination configurations.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

The paginated list of customers.

retrieve#

This method retrieves a customer by its ID. It sends a request to the Get Customer API route.

Example#

To retrieve a customer by its ID:

Code
1sdk.admin.customer.retrieve("cus_123")2.then(({ customer }) => {3  console.log(customer)4})

To specify the fields and relations to retrieve:

Code
1sdk.admin.customer.retrieve("cus_123", {2  fields: "id,*groups"3})4.then(({ customer }) => {5  console.log(customer)6})

Learn more about the fields property in the API reference.

Parameters#

idstring
The customer's ID.
querySelectParamsOptional
Configure the fields to retrieve in the customer.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

PromisePromise<AdminCustomerResponse>
The customer's details.

delete#

This method deletes a customer by its ID. It sends a request to the Delete Customer API route.

Example#

Code
1sdk.admin.customer.delete("cus_123")2.then(({ deleted }) => {3  console.log(deleted)4})

Parameters#

idstring
The customer's ID.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

The deletion's details.

batchCustomerGroups#

This method manages customer groups for a customer. It sends a request to the Manage Customers API route.

Example#

Code
1sdk.admin.customer.batchCustomerGroups("cus_123", {2  add: ["cusgroup_123"],3  remove: ["cusgroup_321"]4})5.then(({ customer }) => {6  console.log(customer)7})

Parameters#

idstring
The customer's ID.
The groups to add customer to or remove customer from.
headersClientHeadersOptional
Headers to pass in the request

Returns#

PromisePromise<AdminCustomerResponse>
The customers details.

createAddress#

This method creates a customer address. It sends a request to the Create Customer Address API route.

Example#

Code
1sdk.admin.customer.createAddress("cus_123", {2  address_1: "123 Main St",3  city: "Anytown",4  country_code: "US",5  postal_code: "12345"6})7.then(({ customer }) => {8  console.log(customer)9})

Parameters#

idstring
The customer's ID.
The customer address's details.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

PromisePromise<AdminCustomerResponse>
The customer address's details.

updateAddress#

This method updates a customer address. It sends a request to the Update Customer Address API route.

Example#

Code
1sdk.admin.customer.updateAddress("cus_123", "cus_addr_123", {2  address_1: "123 Main St",3  city: "Anytown",4  country_code: "US",5  postal_code: "12345"6})7.then(({ customer }) => {8  console.log(customer)9})

Parameters#

idstring
The customer's ID.
addressIdstring
The customer address's ID.
The customer address's details.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

PromisePromise<AdminCustomerResponse>
The customer address's details.

deleteAddress#

This method deletes a customer address. It sends a request to the Delete Customer Address API route.

Example#

Code
1sdk.admin.customer.deleteAddress("cus_123", "cus_addr_123")2.then(({ customer }) => {3  console.log(customer)4})

Parameters#

idstring
The customer's ID.
addressIdstring
The customer address's ID.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

PromisePromise<AdminCustomerResponse>
The customer address's details.

retrieveAddress#

This method retrieves a customer address by its ID. It sends a request to the Get Customer Address API route.

Example#

Code
1sdk.admin.customer.retrieveAddress("cus_123", "cus_addr_123")2.then(({ customer }) => {3  console.log(customer)4})

Parameters#

idstring
The customer's ID.
addressIdstring
The customer address's ID.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

PromisePromise<AdminCustomerResponse>
The customer address's details.

listAddresses#

This method retrieves a list of customer addresses. It sends a request to the List Customer Addresses API route.

Example#

Code
1sdk.admin.customer.listAddresses("cus_123")2.then(({ addresses }) => {3  console.log(addresses)4})

Parameters#

idstring
The customer's ID.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

PromisePromise<AdminCustomerResponse>
The list of customer addresses.
Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break