Skip to main content

Working with Account Addresses

Account addresses allow users to save and reuse shipping or billing addresses during checkout. They are the recommended approach for most B2B and D2C storefronts, providing robust features and flexibility for authenticated users.

Account addresses are saved addresses associated with a registered customer account. They allow returning users to quickly select from previously used shipping or billing addresses during checkout, improving convenience and reducing friction. Managing account addresses is useful for B2B and D2C storefronts where users may want to save multiple addresses (e.g., home, work, office) and reuse them in future purchases.

Prerequisites

  • You have installed and configured the @epcc-sdk/sdks-shopper package.
  • The user is authenticated and you have their account ID and Account Management Authentication Token.

Setup

Install and configure the Shopper SDK:

npm install @epcc-sdk/sdks-shopper

Common Use Cases

  • Let a returning user select a shipping or billing address during checkout.
  • Allow a user to add a new address to their account for future use.
  • Set a default address for an account.

Retrieve Saved Addresses for an Account

Use the SDK to fetch all addresses for an account. This is useful for letting a returning user select a shipping or billing address during checkout.

import { getV2AccountAddresses } from "@epcc-sdk/sdks-shopper";

async function fetchAccountAddresses(accountId, accountToken) {
const response = await getV2AccountAddresses({
path: { accountID: accountId },
headers: { "EP-Account-Management-Authentication-Token": accountToken },
});
return response.data?.data || [];
}

Add a New Address to an Account

Allow the user to add a new address and save it to their account for future use.

import { postV2AccountAddress } from "@epcc-sdk/sdks-shopper";

async function addAccountAddress(accountId, accountToken, addressData) {
const response = await postV2AccountAddress({
path: { accountID: accountId },
body: { data: { type: "address", ...addressData } },
headers: { "EP-Account-Management-Authentication-Token": accountToken },
});
return response.data?.data;
}
info

Setting a Default Address

The Account Address service does not provide a direct way to set a default address for an account. If you want to support default addresses in your storefront, you can:

  • Use the name field on the address (e.g., set it to "default") and filter for it in your UI.
  • Track the user's preferred address ID in your application state or database.

When presenting address options to the user, you can highlight or pre-select the default address based on your chosen approach.

Next Steps