# Save an address

> Add a new address to the address book of your ParcelParcel account.

`POST https://services.parcelparcel.com/partners-api/v1/address-book`

This endpoint saves a new address in the address book of your account. The address shows up under **Address book** in MyParcelParcel, and you can use its `id` as `addressBookId` when you [create a shipment](https://www.parcelparcel.com/api-docs/create-shipment/#address-type).

The body uses the same keys as an address in [Create a (draft) shipment](https://www.parcelparcel.com/api-docs/create-shipment/#address-type), so you can save an address exactly as you send it in a shipment.

## 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 the following elements. Every text field can have at most 255 characters.

| Name          | Value    | Required | Comments                                                                                       |
| :------------ | :------- | :------- | :--------------------------------------------------------------------------------------------- |
| countryCode   | (string) | true     | ISO 3166-1 alpha-2 country code, for example `NL` or `US`.                                     |
| companyName   | (string) | false    |                                                                                                |
| contactPerson | (string) | true     | Full name of the contact person.                                                               |
| phone         | (string) | true     |                                                                                                |
| email         | (string) | false    |                                                                                                |
| addressLine1  | (string) | true     |                                                                                                |
| addressLine2  | (string) | false    |                                                                                                |
| zipcode       | (string) | false    |                                                                                                |
| city          | (string) | true     |                                                                                                |
| provinceCode  | (string) | false    | State or province code, for example `TX` for Texas.                                            |
| vatNumber     | (string) | false    |                                                                                                |
| eoriNumber    | (string) | false    | A 2-letter country code followed by 1 to 15 letters or digits, for example `NL123456789`.      |

Saving an address with fewer fields is fine. A shipment still needs all its own required fields, such as `email` and `zipcode`. If the saved address does not have them, add them to the address in the shipment.

## Response

The response body is the saved address. It has the same elements as [Get an address](https://www.parcelparcel.com/api-docs/get-address/#response), including the new `id`.

Note that the response uses the output names: `company`, `stateOrProvince` and `country` (instead of `companyName`, `provinceCode` and `countryCode`). These are the same names as in [List your shipments](https://www.parcelparcel.com/api-docs/list-shipments/#address-fields).

If the request is not valid, the response has an `errors` array with one entry per wrong field:

| Name           | Value    | Comments                          |
| :------------- | :------- | :-------------------------------- |
| errors         | (array)  | One entry per wrong field.        |
| errors.field   | (string) | The name of the field in your body. |
| errors.message | (string) | What is wrong with the field.     |

### Status codes

| Status code     | Meaning                                                                                                                  |
| :-------------- | :----------------------------------------------------------------------------------------------------------------------- |
| 201 Created     | The address is saved. The response is the new address.                                                                   |
| 400 Bad Request | The address is not saved. A required field is missing or empty, a field is too long, or a value is not valid. See `errors`. |

## Examples

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

### Request example - Save a recipient in the United States

```bash cURL
curl --location --request POST 'https://services.parcelparcel.com/partners-api/v1/address-book' \
--header 'X-PP-API: {YourAPIKey}@{YourAPISecret}' \
--header 'Content-Type: application/json' \
--data-raw '{
  "countryCode": "US",
  "companyName": "Acme Inc.",
  "contactPerson": "Jane Smith",
  "phone": "+12125550100",
  "email": "jane@acme.com",
  "addressLine1": "350 5th Ave",
  "zipcode": "10118",
  "city": "New York",
  "provinceCode": "NY"
}'
```
```http HTTP
POST /partners-api/v1/address-book HTTP/1.1
Host: services.parcelparcel.com
X-PP-API: {YourAPIKey}@{YourAPISecret}
Content-Type: application/json

{
  "countryCode": "US",
  "companyName": "Acme Inc.",
  "contactPerson": "Jane Smith",
  "phone": "+12125550100",
  "email": "jane@acme.com",
  "addressLine1": "350 5th Ave",
  "zipcode": "10118",
  "city": "New York",
  "provinceCode": "NY"
}
```

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

### Response example - Address saved (201)

```json
{
  "id": 456,
  "company": "Acme Inc.",
  "contactPerson": "Jane Smith",
  "phone": "+12125550100",
  "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 - Address not valid (400)

```json
{
  "errors": [
    {
      "field": "contactPerson",
      "message": "contactPerson is required."
    },
    {
      "field": "countryCode",
      "message": "countryCode must be a known 2-letter ISO country code."
    }
  ]
}
```
