Broadleaf Microservices
  • v1.0.0-latest-prod

Customer Saved Addresses

Customers may wish to store addresses within the system. The following operations allow you to read, update, and delete customer addresses.

Note

To operate on the customer’s saved addresses, the customer must be authenticated and their access token must be provide to the function call.

List Customer Addresses

Operation

CustomerClient#listCustomerAddresses(customerId, options);

Parameters

Parameter Type Required? Description

customerId

string

Provide a customer id who’s addresses you want to fetch.

options

PageableClientCallOptions

Options passed to the HTTP request call to customize the request configuration. Including paging related options.

Response

This function returns a list of CustomerAddresses.

Example

Example of retrieving a customer’s saved addresses
const customerAddresses = await customerClient.listCustomerAddresses(
  'CUSTOMER_ID',
  { accessToken }
);

console.log(customerAddresses);

Get Customer Address

Operation

CustomerClient#getCustomerAddress(customerId, customerAddressId, options);

Parameters

Parameter Type Required? Description

customerId

string

Provide the customer id which owns the address.

customerAddressId

string

Provide the customer address id to retrieve.

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a CustomerAddress.

Example

Example of retrieving a customer’s saved address by it’s id
const customerAddress = await customerClient.getCustomerAddress(
  'CUSTOMER_ID',
  'CUSTOMER_ADDRESS_ID',
  { accessToken }
);

console.log(customerAddress);

Add Customer Address

Operation

CustomerClient#addCustomerAddress(customerId, customerAddress, options);

Parameters

Parameter Type Required? Description

customerId

string

Provide the customer id which owns the address.

customerAddress

CustomerAddress

Provide the customer address data to add.

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a CustomerAddress.

Example

Example of adding a new saved address for a customer
const address: CustomerAddress = {
  name: 'Home Address',
  fullName: 'Customer Full Name',
  addressLine1: '123 Street Drive',
  city: 'City',
  stateProvinceRegion: 'TX'
  postalCode: '12345',
  defaultBillingAddress: false,
  defaultShippingAddress: false,
}

const customerAddress = await customerClient.addCustomerAddress(
  'CUSTOMER_ID',
  address,
  { accessToken }
);

console.log(customerAddress);

Update Customer Address

Operation

CustomerClient#updateCustomerAddress(customerId, customerAddressId, updatedAddress, options);

Parameters

Parameter Type Required? Description

customerId

string

Provide the customer id which owns the address.

customerAddressId

string

Provide the customer address id to update.

updatedAddress

CustomerAddress

Provide the customer address data to update.

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a CustomerAddress.

Example

Example of updating a saved address for a customer
const updatedAddress: CustomerAddress = {
  name: 'Work Address',
  fullName: 'Customer Full Name',
  addressLine1: '456 Street Drive',
  city: 'City',
  stateProvinceRegion: 'TX'
  postalCode: '54321',
  defaultBillingAddress: true,
  defaultShippingAddress: false,
}

const customerAddress = await customerClient.updateCustomerAddress(
  'CUSTOMER_ID',
  'CUSTOMER_ADDRESS_ID',
  updatedAddress,
  { accessToken }
);

console.log(customerAddress);

Delete Customer Address

Operation

CustomerClient#deleteCustomerAddress(customerId, customerAddressId, options);

Parameters

Parameter Type Required? Description

customerId

string

Provide the customer id which owns the address.

customerAddressId

string

Provide the customer address id to delete.

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns void.

Example

Example of deleting a saved address for a customer
await customerClient.deleteCustomerAddress(
  'CUSTOMER_ID',
  'CUSTOMER_ADDRESS_ID',
  { accessToken }
);