Work with address types

An address type is a string, such as Billing or Shipping, that can be associated with a Commerce address.

Address types help shoppers, business users, and administrators keep track of profile and account addresses. Address types can also be used in integrations, as they are included with address details in the bodies of webhooks and API responses. By default, two address types are available in Commerce: Shipping and Billing.

Note: When multiple sites are run from a single Commerce instance, a shopper’s profile is shared by all sites. This means that any billing or shipping addresses added to a shopper’s profile are available to all sites. By default, any profile address (with any country) can be marked as a shipping or billing address, even if the address might not be a valid shipping or billing address on some sites, or in some account contexts.

Address types can be assigned to profile and account addresses, as well as addresses used in account registration requests. Business users who work with account addresses can automatically select existing address types when creating or editing addresses in the administration interface. However, since default widgets do not include support for address types, shoppers, delegated administrators, and Agent Console users will not be able to work with address types unless you customize widgets that let them see and work with addresses. You can also assign address types with REST API endpoints.

The Address Types resource in the Admin API includes endpoints for creating and working with address types. The Profiles and Organizations resources include endpoints that you can use to set the values of properties of address types.

View address types

You can view address types using the REST API. To view existing address types, first log into the Admin API on the administration server using an account that has the Administrator role. For example:

POST /ccadmin/v1/mfalogin HTTP/1.1
Content-Type: application/x-www-form-urlencoded

grant_type=password&username=admin1@example.com&password=A3ddj3w2&totp_code=365214

Then issue a GET request to the ccadmin/v1/addressTypes endpoint.

The following is an example of the response returned. Note that BILLING and SHIPPING are default address types that are included with Commerce.

{
  "total": 3,
  "totalResults": 3,
  "offset": 0,
  "limit": 250,
  "links": [
    {
      "rel": "self",
      "href": "http://myserver.example.com:7002/ccadminui/v1/addressTypes"
    }
  ],
  "sort": [
    {
      "property": "displayName",
      "order": "asc"
    }
  ],
  "items": [
    {
      "displayName": "Billing",
      "repositoryId": "BILLING",
      "id": "BILLING"
    },
    {
      "displayName": "Office",
      "repositoryId": "at100001",
      "id": "at100001"
    },
    {
      "displayName": "Shipping",
      "repositoryId": "SHIPPING",
      "id": "SHIPPING"
    }
  ]
}

Create an address type

To create a new address type, issue a POST request to the /ccadmin/v1/addressTypes endpoint on the administration server. Specify the value of the displayName property in the body of the request. For example:

If the address type is created successfully, the response body returned includes the ID for the new address type and a link to the URL used in the request:

{
  "displayName": "Main Campus",
  "repositoryId": "at100002",
  "links": [
    {
      "rel": "self",
      "href": "http://myserver.example.com:7002/ccadminui/v1/addressTypes"
    }
  ],
  "id": "at100002"
}

Assign a type to an address

Business users who work with account addresses can automatically select existing address types when creating or editing addresses in the administration interface. For example, a Commerce administrator can select address types when creating or editing an account's addresses. For more information, see Work with account addresses.

You can also assign an address type with REST API endpoints that create or update profile and account addresses. The following sample request assigns the Main Campus address type to a specified account address.

PUT /ccadmin/v1/organizations/or-100001/secondaryAddresses/at100001  HTTP/1.1
Content-Type: application/json
Authorization: Bearer <access_token>

{
    "addressType":"Main Campus"
}