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.
Coverageri:link
Method | Commercetools | SAPCC | BigCommerce | SFCC | Magento |
---|---|---|---|---|---|
createCustomerAddress | ✅ | ✅ | ✅ | ✅ | ✅ |
getCustomerAddresses | ✅ | ✅ | ✅ | ✅ | ✅ |
updateCustomerAddress | ✅ | ✅ | ✅ | ✅ | ✅ |
deleteCustomerAddress | ✅ | ✅ | ✅ | ✅ | ✅ |
getOrders | ✅ | ✅ | ✅ | ✅ | ✅ |
getOrderDetails | ✅ | ✅ | ✅ | ✅ | ✅ |
createCustomerAddressri:link
The createCustomerAddress
method is used to add a new address to the currently authenticated customer's address book.
Usageri:link
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",
},
});
Typeri:link
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>;
}
getCustomerAddressesri:link
The getCustomerAddresses
method retrieves all the addresses associated with the currently authenticated customer.
Usageri:link
const { addresses } = await sdk.unified.getCustomerAddresses();
Typeri:link
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>;
}
updateCustomerAddressri:link
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.
Usageri:link
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",
},
});
Typeri:link
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>;
}
deleteCustomerAddressri:link
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.
Usageri:link
await sdk.unified.deleteCustomerAddress({
id: "1",
});
Typeri:link
export type DeleteCustomerAddress = (args: DeleteCustomerAddressArgs) => Promise<void>;
export interface DeleteCustomerAddressArgs {
id: SfId;
}
getOrdersri:link
The getOrders
method allows you to fetch a list of orders placed by the currently authenticated customer.
Usageri:link
const { orders } = await sdk.unified.getOrders();
Typeri:link
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;
}
getOrderDetailsri:link
The getOrderDetails
method allows you to fetch the details of a specific order placed by the currently authenticated customer.
Usageri:link
const { order } = await sdk.unified.getOrderDetails({
id: "1",
});
Typeri:link
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;
};