# Managing a shopper's address

Managing a shopper's address is crucial to ensuring a smooth and efficient shopping experience. Whether adding a new address or updating an existing one, the Commerce API allows you to handle address data for individual shoppers easily. This document outlines the steps to create or update a shopper's address using the API, including necessary HTTP requests, endpoint details, and required fields.

## Creating or updating a shopper's address

To manage a shopper's address, you can either create a new address or update an existing one using the Commerce API. This process involves sending a `POST` request to the appropriate endpoint with the required address details and your access token. By providing a unique nickname for the address, you ensure that the system can distinguish between creating a new address and updating an existing one.

To create or update a shopper's address, send a [`POST /v1/shoppers/me/addresses`](https://docs.digitalriver.com/commerce-api-references/shopper-apis/shoppers/addresses#v1-shoppers-me-addresses-1) request and include your access token. Ensure you provide a unique nickname for the address entry. An existing address with the same nickname will be updated; otherwise, a new address will be created. See the [query parameters](https://docs.digitalriver.com/commerce-api-references/shopper-apis/shoppers/addresses#v1-shoppers-me-addresses-1) for a description of the query parameters.&#x20;

The address object contains several parameters to describe the shopper's address:

* `nickName` (string): A unique nickname for the address entry. Ensures distinction between new and existing addresses.
* `isDefault` (boolean): Indicates if the address is the default shipping address.
* `firstName` (string): The first name of the shopper.
* `lastName` (string): The last name of the shopper.
* `companyName` (string): The name of the company, if applicable.
* `line1` (string): The first line of the address.
* `line2` (string): The second line of the address, if necessary.
* `line3` (string): The third line of the address, if necessary.
* `city` (string): The city name.
* `countrySubdivision` (string): The subdivision of the country (e.g., state or province).
* `postalCode` (string): The postal code.
* `country` (string): The two-letter country code.
* `countryName` (string): The full name of the country.
* `countyName` (string): The county name.
* `phoneNumber` (string): The phone number.
* `phoneticFirstName` (string): The phonetic spelling of the first name is useful for some languages.
* `phoneticLastName` (string): The phonetic spelling of the last name.
* `division` (string): The division within the company, if applicable.

Here’s an example using cURL:

{% tabs %}
{% tab title="cURL" %}

<pre class="language-http"><code class="lang-http"><strong>curl --location --request POST 'https://api.digitalriver.com/v1/shoppers/me/addresses' \
</strong>--header 'authorization: bearer [Your_Access_Token]'\
...
--data-raw '{
  "address": {
    "nickName": "test",
    "isDefault": "true",
    "firstName": "Jon",
    "lastName": "Doe",
    "companyName": "Digital River",
    "line1": "10380 Bren Road West",
    "line2": "string",
    "line3": "string",
    "city": "Minnetonka",
    "countrySubdivision": "MN",
    "postalCode": "55343",
    "country": "US",
    "countryName": "United States",
    "countyName": "Hennepin",
    "phoneNumber": "555-253-1234",
    "phoneticFirstName": "クリス",
    "phoneticLastName": "ミラー",
    "division": "製品開発"
  }
}
</code></pre>

{% endtab %}
{% endtabs %}

You will receive a `204 No Content` response.

## Getting an address by identifier

To retrieve specific address information associated with a shopper, use the unique `addressId`. This can be particularly useful for verifying details or making targeted updates. Follow the instructions below to send a request to Commerce API and get the desired address data.

To get an address by identifier, send a [`GET /v1/shoppers/me/addresses/{addressId}`](https://docs.digitalriver.com/commerce-api-references/shopper-apis/shoppers/addresses#v1-shoppers-me-addresses-addressid) request. Include the `addressId` in the endpoint URL and your access token in the request header. Here's an example cURL command:

{% tabs %}
{% tab title="cURL" %}
{% code overflow="wrap" %}

```http
curl --location --request GET 'https://api.digitalriver.com/v1/shoppers/addresses/{addressId}' \
--header 'authorization: bearer [Your_Access_Token]'\
...
```

{% endcode %}
{% endtab %}

{% tab title="200 OK response" %}
{% code overflow="wrap" %}

```json
{
  "address": {
    "uri": "https://api.digitalriver.com/v1/shoppers/me/addresses/1234567890",
    "id": 1655007697,
    "nickName": "test",
    "isDefault": "true",
    "firstName": "Jon",
    "lastName": "Doe",
    "line1": "10380 Bren Road West",
    "line2": "string",
    "city": "Minnetonka",
    "countrySubdivision": "MN",
    "postalCode": "55343",
    "country": "US",
    "countryName": "United States",
    "phoneNumber": "952-253-1234",
    "phoneticFirstName": "クリス",
    "phoneticLastName": "ミラー",
    "division": "製品開発"
  }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

You will receive a `200 OK` response.

## Getting all shopper addresses

To efficiently manage and review all addresses associated with a shopper, the Commerce API provides an endpoint to retrieve this data. By fetching all addresses, you can ensure complete visibility over the shopper's address records, facilitating easier updates and accuracy in order processing.

To get all shopper addresses, send a [`GET /v1/shoppers/me/addresses`](https://docs.digitalriver.com/commerce-api-references/shopper-apis/shoppers/addresses#v1-shoppers-me-addresses) request. Include your access token in the request header. Here's an example cURL command:

{% tabs %}
{% tab title="cURL" %}
{% code overflow="wrap" %}

```http
curl --location --request GET 'https://api.digitalriver.com/v1/shoppers/addresses' \
--header 'authorization: bearer [Your_Access_Token]'\
...
```

{% endcode %}
{% endtab %}

{% tab title="200 OK response" %}
{% code overflow="wrap" %}

```json
{
  "addresses": {
    "uri": "https://api.digitalriver.com/v1/shoppers/me/addresses",
    "address": [
      {
        "uri": "https://api.digitalriver.com/v1/shoppers/me/addresses/1234567890",
        "nickName": "test",
        "isDefault": "true"
      }
    ]
  }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Deleting a shopper's address

You may need to delete outdated or incorrect addresses to manage your shopper address list. The Commerce API lets you remove a shopper’s address by issuing a `DELETE` request. This ensures your address records remain accurate and up-to-date.

To delete a shopper's address, send a [`DELETE /v1/shoppers/me/addresses/{addressId}`](https://docs.digitalriver.com/commerce-api-references/shopper-apis/shoppers/addresses#v1-shoppers-me-addresses-addressid-1) request with the address identifier (`addressId`) and include your access token in the request header. Here is an example cURL command:

{% tabs %}
{% tab title="cUR." %}
{% code overflow="wrap" %}

```http
curl --location --request DELETE 'https://api.digitalriver.com/v1/shoppers/addresses/{addressId}' \
--header 'authorization: bearer [Your_Access_Token]'\
...De
```

{% endcode %}
{% endtab %}
{% endtabs %}

You will receive a `204 No Content` response.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.digitalriver.com/commerce-api/shopper-apis/shoppers/managing-a-shoppers-address.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
