# Update an address

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

Adds or replaces the address for a subscription. If an address is already present for the specified label, it will be replaced otherwise new address is added with that label.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/addresses \
     -u {site_api_key}:\
     -d subscription_id="__test__KyVnHhSBWm3I82re" \
     -d label="shipping_address" \
     -d first_name="Benjamin" \
     -d last_name="Ross" \
     -d addr="PO Box 9999" \
     -d city="Walnut" \
     -d state="California" \
     -d zip="91789" \
     -d country="US"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Address.Update()
		.SubscriptionId("__test__KyVnHhSBWm3I82re")
		.Label("shipping_address")
		.FirstName("Benjamin")
		.LastName("Ross")
		.Addr("PO Box 9999")
		.City("Walnut")
		.State("California")
		.Zip("91789")
		.Country("US")
		.Request();

Address address = result.Address;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    addressAction "github.com/chargebee/chargebee-go/v3/actions/address"
    "github.com/chargebee/chargebee-go/v3/models/address"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := addressAction.Update(&address.UpdateRequestParams{
        SubscriptionId : "__test__KyVnHhSBWm3I82re",
        Label : "shipping_address",
        FirstName : "Benjamin",
        LastName : "Ross",
        Addr : "PO Box 9999",
        City : "Walnut",
        State : "California",
        Zip : "91789",
        Country : "US",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Address := res.Address
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.AddressUpdateRequest{
    SubscriptionId : "__test__KyVnHhSBWm3I82re",
    Label : "shipping_address",
    FirstName : "Benjamin",
    LastName : "Ross",
    Addr : "PO Box 9999",
    City : "Walnut",
    State : "California",
    Zip : "91789",
    Country : "US",
}
  res, err := client.Address.Update(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Address := res.Address
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Address.update()
            .subscriptionId("__test__KyVnHhSBWm3I82re")
            .label("shipping_address")
            .firstName("Benjamin")
            .lastName("Ross")
            .addr("PO Box 9999")
            .city("Walnut")
            .state("California")
            .zip("91789")
            .country("US")
            .request();

        Address address = result.address();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.address.Address;
import com.chargebee.v4.models.address.params.AddressUpdateParams;
import com.chargebee.v4.models.address.responses.AddressUpdateResponse;

public class AddressUpdate {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        AddressUpdateParams params = AddressUpdateParams.builder()
            .subscriptionId("__test__KyVnHhSBWm3I82re")
            .label("shipping_address")
            .firstName("Benjamin")
            .lastName("Ross")
            .addr("PO Box 9999")
            .city("Walnut")
            .state("California")
            .zip("91789")
            .country("US")
            .build();

        AddressUpdateResponse response = client.addresses().update(params);

        Address address = response.getAddress();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.address.update({
        subscription_id: "__test__KyVnHhSBWm3I82re",
        label: "shipping_address",
        first_name: "Benjamin",
        last_name: "Ross",
        addr: "PO Box 9999",
        city: "Walnut",
        state: "California",
        zip: "91789",
        country: "US"
    });

    console.log(result);
    const address = result.address;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->address()->update([
    "subscription_id" => "__test__KyVnHhSBWm3I82re",
    "label" => "shipping_address",
    "first_name" => "Benjamin",
    "last_name" => "Ross",
    "addr" => "PO Box 9999",
    "city" => "Walnut",
    "state" => "California",
    "zip" => "91789",
    "country" => "US"
]);
$address = $result->address;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Address.update(
    cb_client.Address.UpdateParams(
        subscription_id="__test__KyVnHhSBWm3I82re",
        label="shipping_address",
        first_name="Benjamin",
        last_name="Ross",
        addr="PO Box 9999",
        city="Walnut",
        state="California",
        zip="91789",
        country="US"
    )
)
address = response.address
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Address.update({
  :subscription_id => "__test__KyVnHhSBWm3I82re",
  :label => "shipping_address",
  :first_name => "Benjamin",
  :last_name => "Ross",
  :addr => "PO Box 9999",
  :city => "Walnut",
  :state => "California",
  :zip => "91789",
  :country => "US"
})

address = result.address
```

## Sample Response

```json
{
  "address": {
    "addr": "PO Box 9999",
    "city": "Walnut",
    "country": "US",
    "first_name": "Benjamin",
    "label": "shipping_address",
    "last_name": "Ross",
    "object": "address",
    "state": "California",
    "state_code": "CA",
    "subscription_id": "__test__KyVnHhSBWm3I82re",
    "validation_status": "not_validated",
    "zip": "91789"
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/addresses

## Input Parameters

- `subscription_id` (required, string, max chars=50)
  A unique and immutable identifier for the subscription. If not provided, it is autogenerated.

- `label` (required, string, max chars=50)
  Label to identify the address. This is unique for all the address for a subscription.

- `first_name` (optional, string, max chars=150)
  First name.

- `last_name` (optional, string, max chars=150)
  Last name.

- `email` (optional, string, max chars=70)
  Email.

- `company` (optional, string, max chars=250)
  Company name.

- `phone` (optional, string, max chars=50)
  Phone number.

- `addr` (optional, string, max chars=150)
  Address line 1.

- `extended_addr` (optional, string, max chars=150)
  Address line 2.

- `extended_addr2` (optional, string, max chars=150)
  Address line 3.

- `city` (optional, string, max chars=50)
  Name of the city.

- `state_code` (optional, string, max chars=50)
  The [ISO 3166-2 state/province code](https://www.iso.org/obp/ui/#search/code) without the country prefix. Currently supported for USA, Canada, India and UAE. For instance, for Arizona (USA), set `state_code` as `AZ` (not `US-AZ` ). For Tamil Nadu (India), set as `TN` (not `IN-TN` ). For British Columbia (Canada), set as `BC` (not `CA-BC` ). For Dubai (UAE), set as `DU` (not `AE-DU` ).

- `state` (optional, string, max chars=50)
  The state/province name. Is set by Chargebee automatically for US, Canada, India and UAE, if `state_code` is provided.

- `zip` (optional, string, max chars=20)
  Zip or postal code. The number of characters is validated according to the rules [specified here](https://chromium-i18n.appspot.com/ssl-address) .

- `country` (optional, string, max chars=50)
  The billing address country of the customer. Must be one of [ISO 3166 alpha-2 country code](https://www.iso.org/iso-3166-country-codes.html) .
  
  **Note**: If you enter an invalid country code, the system will return an error.
  
  **Brexit**
  
  If you have enabled [EU VAT](https://www.chargebee.com/docs/eu-vat.html) in 2021 or later, or have [manually enable](https://www.chargebee.com/docs/brexit.html#what-needs-to-be-done-in-chargebee) the Brexit configuration, then `XI` (the code for **United Kingdom - Northern Ireland**) is available as an option.
  
  .

- `validation_status` (optional, enumerated string, default=not_validated)
  The address verification status.
  Possible enum values:
    - `not_validated`
      Address is not yet validated.
    - `valid`
      Address was validated successfully.
    - `partially_valid`
      The address is valid for taxability but has not been validated for shipping.
    - `invalid`
      Address is invalid.

## Returns

- `address` (Address object)
  Resource object representing address
