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#
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.
Configure the fields to retrieve in the customer.
Headers to pass in the request. This is where you include the authorization JWT registration token.
Returns#
Promise
Promise<StoreCustomerResponse>The customer's details.
Promise
Promise<StoreCustomerResponse>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#
Parameters#
The customer's details to update.
Configure the fields to retrieve in the customer.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCustomerResponse>The customer's details.
Promise
Promise<StoreCustomerResponse>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#
Parameters#
Configure the fields to retrieve in the customer.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCustomerResponse>The customer's details.
Promise
Promise<StoreCustomerResponse>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#
Parameters#
The address's details.
Configure the fields to retrieve in the customer.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCustomerResponse>The customer's details.
Promise
Promise<StoreCustomerResponse>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#
Parameters#
addressId
stringThe details to update in the address.
Configure the fields to retrieve in the customer.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCustomerResponse>The customer's details.
Promise
Promise<StoreCustomerResponse>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:
To configure the pagination, pass the limit
and offset
query parameters.
For example, to retrieve only 10 items and skip 10 items:
Using the fields
query parameter, you can specify the fields and relations to retrieve
in each address:
Learn more about the fields
property in the API reference.
Parameters#
Configure the fields to retrieve in the addresses.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCustomerAddressListResponse>The paginated list of addresses.
Promise
Promise<StoreCustomerAddressListResponse>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:
To specify the fields and relations to retrieve:
Learn more about the fields
property in the API reference.
Parameters#
addressId
stringConfigure the fields to retrieve in the address.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCustomerAddressResponse>The address's details.
Promise
Promise<StoreCustomerAddressResponse>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#
Parameters#
addressId
stringHeaders to pass in the request.
Returns#
Promise
Promise<StoreCustomerAddressDeleteResponse>The deletion's details.
Promise
Promise<StoreCustomerAddressDeleteResponse>