You are reading the documentation for v7.x and earlier, which is no longer the latest version. Switch to v8.x
createUserAddress
Method creating a new customer address in SAP Commerce Cloud.
This method sends a POST request to the createAddress endpoint of the Alokai Middleware. In turn, it exchanges data with the createAddress endpoint exposed by the SAP OCC API Address Controller.
The method creates an address for a customer based on the vsf-sap-token cookie (which is assigned to that customer). The cookie must be present in the browser for the method to work properly.
SAP Commerce's doesn't allow setting "district" field in the newly created address. If you want to find workaround for this problem, check Limitations page in our documentation.
Signature
export declare function createUserAddress<Res extends Address = Address,
Props extends CreateAddressProps = CreateAddressProps>(
props: Props,
options?: MethodOptions
): Promise<Res>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
props | Required | Props | Parameter object which can be used with this method. Refer to its type definition to learn about possible properties. |
options | Optional | MethodOptions | Options that can be passed to additionally configure the request or customize the logic in a plugin. |
Returns
Returns a representation of an Address.
Referenced Types
Examples
Creating a customer address.
import { sdk } from '~/sdk';
import { CreateAddressProps } from '@vsf-enterprise/sapcc-types';
const props: CreateAddressProps = {
address: {
firstName: 'Integration',
lastName: 'Test',
line1: 'Test',
postalCode: '54-025',
titleCode: 'mr',
country: { isocode: 'GB' },
town: 'Radom'
}
};
const address = await sdk.commerce.createUserAddress(props);Creating a customer address and selecting response fields.
import { sdk } from '~/sdk';
import { CreateAddressProps } from '@vsf-enterprise/sapcc-types';
const props: CreateAddressProps = {
address: {
firstName: 'Integration',
lastName: 'Test',
line1: 'Test',
postalCode: '54-025',
titleCode: 'mr',
country: { isocode: 'GB' },
town: 'Radom'
},
fields: 'firstName,lastName'
};
const address = await sdk.commerce.createUserAddress(props);