Customer
The Customer Address methods can be used to create, fetch, update, or delete an authenticated customer's saved addresses.
These methods require a customer to be authenticated
Read more about the authentication methods to set up authentication with the Unified Data Layer.
Coverage
Method | Commercetools | SAPCC | BigCommerce | SFCC | Magento |
---|---|---|---|---|---|
createCustomerAddress | ✅ | ✅ | ✅ | ✅ | ✅ |
getCustomerAddresses | ✅ | ✅ | ✅ | ✅ | ✅ |
updateCustomerAddress | ✅ | ✅ | ✅ | ✅ | ✅ |
deleteCustomerAddress | ✅ | ✅ | ✅ | ✅ | ✅ |
getOrders | ✅ | ✅ | ✅ | ✅ | ✅ |
getOrderDetails | ✅ | ✅ | ✅ | ✅ | ✅ |
createCustomerAddress
The createCustomerAddress
method is used to add a new address to the currently authenticated customer's address book.
Usage
const { address } = await sdk.unified.createCustomerAddress({
address: {
address1: "Some Street",
city: "New York",
country: "United States",
firstName: "John",
lastName: "Doe",
phoneNumber: "+12065550100",
postalCode: "54-022",
state: "NY",
titleCode: "Mr",
},
});
Type
export type CreateCustomerAddress = (args: CreateCustomerAddressArgs) => Promise<{
address: SfCustomerAddress;
}>;
export interface CreateCustomerAddressArgs {
address: SfCreateAddressBody;
}
export interface SfCustomerAddress {
id: SfId;
address1: Maybe<string>;
address2?: Maybe<string>;
city: Maybe<string>;
country: Maybe<string>;
firstName: Maybe<string>;
lastName: Maybe<string>;
phoneNumber: Maybe<string>;
postalCode: Maybe<string>;
state: Maybe<string>;
titleCode: Maybe<string>;
}
getCustomerAddresses
The getCustomerAddresses
method retrieves all the addresses associated with the currently authenticated customer.
Usage
const { addresses } = await sdk.unified.getCustomerAddresses();
Type
export type GetCustomerAddresses = () => Promise<{
addresses: SfCustomerAddress[];
}>;
export interface SfCustomerAddress {
id: SfId;
address1: Maybe<string>;
address2?: Maybe<string>;
city: Maybe<string>;
country: Maybe<string>;
firstName: Maybe<string>;
lastName: Maybe<string>;
phoneNumber: Maybe<string>;
postalCode: Maybe<string>;
state: Maybe<string>;
titleCode: Maybe<string>;
}
updateCustomerAddress
The updateCustomerAddress
method allows the currently authenticated customer to update one of their existing addresses using the ID of the address and the new address information.
Usage
const { address } = await sdk.unified.updateCustomerAddress({
id: "1",
address: {
address1: "Some Street",
city: "New York",
country: "United States",
firstName: "John",
lastName: "Doe",
phoneNumber: "+12065550100",
postalCode: "54-022",
state: "NY",
titleCode: "Mr",
},
});
Type
export type UpdateCustomerAddress = (args: UpdateCustomerAddressArgs) => Promise<{
address: SfCustomerAddress;
}>;
export interface UpdateCustomerAddressArgs {
id: SfId;
address: SfCreateAddressBody;
}
export interface SfCreateAddressBody {
address1: string;
address2?: Maybe<string>;
city: string;
country: string;
firstName: string;
lastName: string;
phoneNumber: string;
postalCode: string;
state: string;
titleCode: string;
}
export interface SfCustomerAddress {
id: SfId;
address1: Maybe<string>;
address2?: Maybe<string>;
city: Maybe<string>;
country: Maybe<string>;
firstName: Maybe<string>;
lastName: Maybe<string>;
phoneNumber: Maybe<string>;
postalCode: Maybe<string>;
state: Maybe<string>;
titleCode: Maybe<string>;
}
deleteCustomerAddress
The deleteCustomerAddress
method allows the currently authenticated customer to remove an address from their address book. It takes an object as an argument, which includes the id
of the address to be deleted.
Usage
await sdk.unified.deleteCustomerAddress({
id: "1",
});
Type
export type DeleteCustomerAddress = (args: DeleteCustomerAddressArgs) => Promise<void>;
export interface DeleteCustomerAddressArgs {
id: SfId;
}
getOrders
The getOrders
method allows you to fetch a list of orders placed by the currently authenticated customer.
Usage
const { orders } = await sdk.unified.getOrders();
Type
export type GetOrders = (args?: GetOrdersArgs) => Promise<{
orders: SfOrderListItem[];
pagination: SfPagination;
}>;
export type GetOrdersArgs = {
pageSize?: number;
currentPage?: number;
};
export interface SfOrderListItem {
id: SfId;
orderDate: string;
totalPrice: SfMoney;
status: string;
}
getOrderDetails
The getOrderDetails
method allows you to fetch the details of a specific order placed by the currently authenticated customer.
Usage
const { order } = await sdk.unified.getOrderDetails({
id: "1",
});
Type
export type GetOrderDetails = (args: GetOrderArgs) => Promise<SfOrder>;
export type GetOrderArgs = {
id: string;
}
export interface SfOrder {
id: SfId;
orderDate: string;
status: string;
lineItems: SfOrderLineItem[];
subtotalPrice: SfMoney;
totalShippingPrice: SfMoney;
totalTax: SfMoney;
totalPrice: SfMoney;
shippingAddress: SfAddress;
billingAddress: Maybe<SfAddress>;
shippingMethod: SfShippingMethod;
paymentMethod: string;
};