# Update an address

> Change one or more fields of a saved address in your ParcelParcel address book.

`PATCH https://services.parcelparcel.com/partners-api/v1/address-book/{addressId}`

This endpoint changes a saved address in the address book of your account. Only the fields you send change. All other fields keep their saved value.

Replace `{addressId}` with the `id` of the address. You get this `id` when you [list your addresses](https://www.parcelparcel.com/api-docs/list-addresses/) or [save an address](https://www.parcelparcel.com/api-docs/create-address/).

You can only update addresses of your own account. An address of another account gives the same `404` as an unknown id.

There is no endpoint to delete an address. You can delete addresses under **Address book** in MyParcelParcel.

## Header

Add the following headers:

| Name         | Value                          |
| :----------- | :----------------------------- |
| Content-Type | application/json               |
| X-PP-API     | `{YourAPIKey}@{YourAPISecret}` |

Don't have an API Key and API Secret yet? Check our [Authentication](https://www.parcelparcel.com/api-docs/authentication/) page to see how to get them in under a minute.

## Body

The request body is a JSON object with only the fields you want to change. The fields are the same as in [Save an address](https://www.parcelparcel.com/api-docs/create-address/#body): `countryCode`, `companyName`, `contactPerson`, `phone`, `email`, `addressLine1`, `addressLine2`, `zipcode`, `city`, `provinceCode`, `vatNumber` and `eoriNumber`. Every text field can have at most 255 characters.

* **Change a field:** send the new value, for example `"phone": "+12125550199"`.
* **Clear an optional field:** send `null` or `""`, for example `"addressLine2": null`.
* **Required fields** (`countryCode`, `contactPerson`, `phone`, `addressLine1` and `city`) cannot be cleared. Sending `null` or `""` for one of them gives a `400` and nothing changes.

If one field is wrong, none of the fields change.

## Response

The response body is the full address after the update. It has the same elements as [Get an address](https://www.parcelparcel.com/api-docs/get-address/#response).

If the request is not valid, the response has an `errors` array with one entry per wrong field, the same as in [Save an address](https://www.parcelparcel.com/api-docs/create-address/#response).

### Status codes

| Status code     | Meaning                                                                                                    |
| :-------------- | :--------------------------------------------------------------------------------------------------------- |
| 200 OK          | The address is updated. The response is the full address.                                                  |
| 400 Bad Request | Nothing changed. You tried to clear a required field, a field is too long, or a value is not valid. See `errors`. |
| 404 Not Found   | We could not find the address in your account. Make sure that the `addressId` is correct.                  |

## Examples

Don't know how to test these requests? Check [our guide](https://www.parcelparcel.com/api-docs/postman-guide/).

### Request example - Change the phone number and clear address line 2

```bash cURL
curl --location --request PATCH 'https://services.parcelparcel.com/partners-api/v1/address-book/456' \
--header 'X-PP-API: {YourAPIKey}@{YourAPISecret}' \
--header 'Content-Type: application/json' \
--data-raw '{
  "phone": "+12125550199",
  "addressLine2": null
}'
```
```http HTTP
PATCH /partners-api/v1/address-book/456 HTTP/1.1
Host: services.parcelparcel.com
X-PP-API: {YourAPIKey}@{YourAPISecret}
Content-Type: application/json

{
  "phone": "+12125550199",
  "addressLine2": null
}
```

Don't forget to change the **X-PP-API** element in the header, or this request will not work.

### Response example - Address updated (200)

```json
{
  "id": 456,
  "company": "Acme Inc.",
  "contactPerson": "Jane Smith",
  "phone": "+12125550199",
  "email": "jane@acme.com",
  "addressLine1": "350 5th Ave",
  "addressLine2": null,
  "zipcode": "10118",
  "city": "New York",
  "stateOrProvince": "NY",
  "country": "US",
  "vatNumber": null,
  "eoriNumber": null,
  "defaultPickup": false
}
```

### Response example - Required field cleared (400)

```json
{
  "errors": [
    {
      "field": "city",
      "message": "city is required."
    }
  ]
}
```

### Response example - EORI number not valid (400)

```json
{
  "errors": [
    {
      "field": "eoriNumber",
      "message": "EORI number must start with a 2-letter country code followed by 1 to 15 alphanumeric characters."
    }
  ]
}
```

### Response example - Address not found (404)

```json
"Address not found"
```
