customer - JS SDK Store Reference

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

create#

This method registers a customer. It sends a request to the Register Customer API route.

You must use the Auth.register method first to retrieve a registration token. Then, pass that registration token in the headers parameter of this method as an authorization bearer header.

Related guide: How to register customer in storefront

Example#

Code
1const token = await sdk.auth.register("customer", "emailpass", {2  "email": "customer@gmail.com",3  "password": "supersecret"4})5
6sdk.store.customer.create(7  {8    "email": "customer@gmail.com"9  },10  {},11  {12    Authorization: `Bearer ${token}`13  }14)15.then(({ customer }) => {16  console.log(customer)17})

Parameters#

The customer's details.
querySelectParamsOptional
Configure the fields to retrieve in the customer.
headersClientHeadersOptional
Headers to pass in the request. This is where you include the authorization JWT registration token.

Returns#

PromisePromise<StoreCustomerResponse>
The customer's details.

update#

This method updates the logged-in customer's details. The customer must be logged in first with the Auth.login method.

It sends a request to the Update Customer API route.

Related guide: How to edit customer's profile in the storefront.

Example#

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

Parameters#

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

Returns#

PromisePromise<StoreCustomerResponse>
The customer's details.

retrieve#

This method retrieves the logged-in customer's details. The customer must be logged in first with the Auth.login method.

It sends a request to the Get Logged-In Customer API route.

Example#

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

Parameters#

querySelectParamsOptional
Configure the fields to retrieve in the customer.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

PromisePromise<StoreCustomerResponse>
The customer's details.

createAddress#

This method creates an address for the logged-in customer. The customer must be logged in first with the Auth.login method.

It sends a request to the Create Address API route.

Related guides: How to manage customer's addresses in the storefront

Example#

Code
1sdk.store.customer.createAddress({2  country_code: "us"3})4.then(({ customer }) => {5  console.log(customer)6})

Parameters#

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

Returns#

PromisePromise<StoreCustomerResponse>
The customer's details.

updateAddress#

This method updates the address of the logged-in customer. The customer must be logged in first with the Auth.login method.

It sends a request to the Update Address API route.

Related guides: How to manage customer's addresses in the storefront

Example#

Code
1sdk.store.customer.updateAddress(2  "caddr_123",3  {4    country_code: "us"5  }6)7.then(({ customer }) => {8  console.log(customer)9})

Parameters#

addressIdstring
The ID of the address to update.
The details to update in the address.
querySelectParamsOptional
Configure the fields to retrieve in the customer.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

PromisePromise<StoreCustomerResponse>
The customer's details.

listAddress#

This method retrieves the logged-in customer's address. The customer must be logged in first with the Auth.login method.

It sends a request to the List Customer's Address API route.

Related guides: How to manage customer's addresses in the storefront

Example#

To retrieve the list of addresses:

Code
1sdk.store.customer.listAddress()2.then(({ addresses, count, offset, limit }) => {3  console.log(addresses)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.store.customer.listAddress({2  limit: 10,3  offset: 104})5.then(({ addresses, count, offset, limit }) => {6  console.log(addresses)7})

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

Code
1sdk.store.customer.listAddress({2  fields: "id,country_code"3})4.then(({ addresses, count, offset, limit }) => {5  console.log(addresses)6})

Learn more about the fields property in the API reference.

Parameters#

Configure the fields to retrieve in the addresses.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

The paginated list of addresses.

retrieveAddress#

This method retrieves an address of the logged-in customer. The customer must be logged in first with the Auth.login method.

It sends a request to the Get Address API route.

Related guides: How to manage customer's addresses in the storefront

Example#

To retrieve an address by its ID:

Code
1sdk.store.customer.retrieveAddress(2  "caddr_123"3)4.then(({ address }) => {5  console.log(address)6})

To specify the fields and relations to retrieve:

Code
1sdk.store.customer.retrieveAddress(2  "caddr_123",3  {4    fields: "id,country_code"5  }6)7.then(({ address }) => {8  console.log(address)9})

Learn more about the fields property in the API reference.

Parameters#

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

Returns#

The address's details.

deleteAddress#

This method deletes an address of the logged-in customer. The customer must be logged in first with the Auth.login method.

It sends a request to the Remove Address API route.

Related guides: How to manage customer's addresses in the storefront

Example#

Code
1sdk.store.customer.deleteAddress("caddr_123")2.then(({ deleted, parent: customer }) => {3  console.log(customer)4})

Parameters#

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

Returns#

The deletion's details.
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