# Update a customer address

```http
PUT https://secure.yoprint.com/v1/api/store/{team_slug}/customer/{hash_id}/address/{id}
```

- API version: v1
- Operation ID: `v1_public_customer_address_update`
- Section: Customers › [Customer addresses](https://developer.yoprint.com/reference/customer-addresses.md)
- Web page: https://developer.yoprint.com/reference/customer-addresses/v1-customer-address-update/
- Authentication: `Authorization: Bearer YOUR_API_KEY`

Saves changes to an address. Addresses already printed on a document are never changed in place: YoPrint keeps the old address for those documents and saves your changes as a new address.

`address_save_result.save_mode` says what happened:

- `updated_in_place_unused` (200): nothing used the address, so it was changed. Same id; `revision_number` went up by one.
- `created_replacement_address_used` (200): a sales order, quote, invoice, shipment, package, purchase order or brand profile uses the address. `data` is a new address with a new id and your changes; it takes over as primary if the old one was. The old address stays on those documents and leaves the current list. Brand profiles keep pointing at the old address: update them to the new id yourself.
- `no_address_fields_changed` (200): the values you sent are the ones saved. Nothing changed.
- `stale_address` (409): you sent `base_revision_number` and someone saved the address since. Nothing changed; `current_address` and `stale_base` show the latest.
- `blocked_superseded_historical_address` (409): the address was already replaced by an edit. Edit `current_address` instead.
- `blocked_external_or_compliance` (409): the address is synced from another system or was redacted.

This answer has no `status` field: `success`, `address_save_result` and, on success, `data`; on a 409 also `message` (the mode).

## Permission

Needs the Manage Customers permission ("Manage All" or "Manage Assigned to User"). Whether the customer is assigned to you is not checked.

## Business rules

- Only billing and shipping addresses of this customer can be updated here; deleted ones can't.
- `is_primary` is not changed here: use Set the primary address.
- Customers synced from Shopify are read-only here: changes are refused with 422 `validation_error` "External customers are read-only. Manage changes from Shopify." System customers (`is_system: true`) are refused the same way ("System customer cannot be modified or deleted.").

## Side effects

- May create a new address (`created_replacement_address_used`). Existing sales orders, quotes, invoices, shipments, and purchase orders keep their saved copy of the old address.

## Path parameters

- `team_slug` (string, required): Your team slug, shown as Team ID next to your API key in Profile. Example `your-team`.
- `hash_id` (string, required): The customer's id (`id` from List customers or Create a customer). A hash id from an earlier answer; unique keys and document numbers (such as `PO0042`) don't work here. Example `EDhVUaC6jbLbed`.
- `id` (string, required): The address's id (`id` from List a customer's addresses). A hash id from an earlier answer; unique keys and document numbers (such as `PO0042`) don't work here. Example `uAu3dAKIaHyAYk`.

## Request body

Content type `application/json`, required.

Fields:

- `address1` (string, optional)
- `address2` (string, optional): Street line 2, such as a suite or unit.
- `base_revision_number` (integer, optional): Protects against concurrent edits: send the `revision_number` you last read, and YoPrint refuses the save with 409 `stale_address` if someone changed the address since.
- `city` (string, optional): The city.
- `country` (string, optional)
- `country_code` (string, optional): When you change `state` without `country_code`, the address's saved country is used to check it.
- `label` (string, optional)
- `note` (string, optional): A note kept with the address, such as delivery instructions.
- `operation_key` (string, optional): Your id for this save. Retrying with the same key and the same values returns the replacement the first try made instead of a 409.
- `postcode` (string, optional): The postal or ZIP code.
- `state` (string, optional): `null` is dropped before the request is read, so it can't clear the state: leave the field out to keep it.
- `state_code` (string, optional): As `state`: `null` is the same as leaving it out.

### Example request

```bash
curl -X PUT 'https://secure.yoprint.com/v1/api/store/your-team/customer/EDhVUaC6jbLbed/address/uAu3dAKIaHyAYk' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Accept: application/json' \
  -H 'X-Yoprint-Decimal-Format: exact-v1' \
  -H 'Content-Type: application/json' \
  -d '{
    "address2": "Dock 5",
    "base_revision_number": 1,
    "operation_key": "address-edit-1001"
  }'
```

## Response

`200` Saved, or nothing to save. `address_save_result.save_mode` says which; `data` is the address to use from now on.

Fields:

- `success` (boolean, required): Always `true`.
- `address_save_result` (object, required): What the save did.
  - `message_code` (string, required): The message code for what happened, identical to `save_mode`.
  - `operation_key` (string | null, required): The key you sent, or one YoPrint made.
  - `save_mode` (string, required): One of: `"updated_in_place_unused"`, `"created_replacement_address_used"`, `"no_address_fields_changed"`, `"stale_address"`, `"blocked_superseded_historical_address"`, `"blocked_external_or_compliance"`.
  - `current_address` (object | null, optional): On a refusal: the address to edit instead.
  - `previous_address` (object | null, optional)
  - `replacement_address` (object | null, optional)
  - `stale_base` (object | null, optional)
- `data` (object, required)
  - `address1` (string | null, required)
  - `id` (string, required)
  - `is_current_source` (boolean, required): False for deleted, replaced, Shopify or redacted addresses. Only current addresses can be picked for new documents or edited.
  - `is_primary` (boolean, required)
  - `label` (string | null, required)
  - `revision_number` (integer, required): Goes up by one on every saved change. Send it back as `base_revision_number` when updating the address to protect against concurrent edits.
  - `role` (string, required): `billing` or `shipping` for customer addresses.
  - `trashed` (boolean, required)
  - `address2` (string | null, optional)
  - `address_family_id` (string | null, optional): Shared by an address and the copies made when it was edited after use.
  - `city` (string | null, optional)
  - `copied_from_address_id` (string | null, optional)
  - `country` (string | null, optional)
  - `country_code` (string | null, optional)
  - `customer_id` (string, optional): Customer addresses only: the customer's id.
  - `external_type` (string | null, optional): `shopify` for an address synced from Shopify.
  - `hold_stock` (boolean, optional): Company locations only; false for customer addresses.
  - `is_default_warehouse` (boolean, optional): Company locations only; false for customer addresses.
  - `is_external` (boolean, optional): True for an address synced from Shopify; such addresses are read-only.
  - `nexus` (boolean, optional): Company locations only; false for customer addresses.
  - `note` (string | null, optional)
  - `owner_id` (string | null, optional): The owner's id: for a customer address, the customer's id (the same as `customer_id`).
  - `owner_type` (string, optional): `customer` for customer addresses. One of: `"customer"`, `"team"`, `"unknown"`.
  - `postal_can_validate` (boolean, optional)
  - `postal_is_valid` (boolean, optional)
  - `postal_validated` (boolean, optional): True once YoPrint has checked the address with its address validator. `postal_can_validate` says whether it could be checked and `postal_is_valid` gives the result. Any edit resets it to false.
  - `postcode` (string | null, optional)
  - `source` (string, optional): `customer` for customer addresses. One of: `"customer"`, `"company_location"`, `"custom"`, `"unknown"`.
  - `state` (string | null, optional)
  - `state_code` (string | null, optional)
  - `superseded_at` (string (date-time) | null, optional)
  - `superseded_by_address_id` (string | null, optional): Set on an old copy: the address that replaced it.
  - `used_by_active_profile` (boolean, optional): True when a brand profile uses it as Ship From. Sent on lists, reads, updates and customer answers; not on create or set-primary.

Example response:

```json
{
  "address_save_result": {
    "current_address": null,
    "message_code": "updated_in_place_unused",
    "operation_key": "address-edit-1001",
    "previous_address": null,
    "replacement_address": null,
    "save_mode": "updated_in_place_unused",
    "stale_base": null
  },
  "data": {
    "address1": "100 Example Street",
    "address2": "Dock 5",
    "address_family_id": null,
    "city": "Springfield",
    "copied_from_address_id": null,
    "country": "United States",
    "country_code": "US",
    "customer_id": "V4keXwwxMQyXw7",
    "external_type": null,
    "hold_stock": false,
    "id": "swtHxyIfOvF62K",
    "is_current_source": true,
    "is_default_warehouse": false,
    "is_external": false,
    "is_primary": true,
    "label": "Warehouse",
    "nexus": false,
    "note": null,
    "owner_id": "V4keXwwxMQyXw7",
    "owner_type": "customer",
    "postal_can_validate": false,
    "postal_is_valid": false,
    "postal_validated": false,
    "postcode": "62701",
    "revision_number": 2,
    "role": "shipping",
    "source": "customer",
    "state": "Illinois",
    "state_code": "IL",
    "superseded_at": null,
    "superseded_by_address_id": null,
    "trashed": false,
    "used_by_active_profile": false
  },
  "success": true
}
```

## Errors

- `401` The API key is missing or wrong (`unauthenticated`).
- `403` You are not allowed to do this. `api_access_not_in_plan`: your team's plan doesn't include API access (Pro and above, with an active subscription or trial), so every request answers this until the team upgrades. When your role lacks the permission the operation needs, the body is only `{"message": "Insufficient Permission"}`. Other refusals use the error envelope, with `unauthorized` or `user_is_not_authorized`.
  - When: Your role has no Manage Customers permission. This 403 has a short body, `{"message": "Insufficient Permission"}`, with no `success` or `error`. Fix: Ask a team owner to give your role Manage Customers.
- `404` Not found. `page_not_found`: the team slug is unknown, you are not a member of the team, or an id in the path is not one of this team's. `code: null`, with a message that starts "No query results for": there is no record with that id.
  - When: The address is deleted, or is not a billing or shipping address of this customer. `error.code` is null and `error.message` names the record type. Fix: Check the ids.
- `409` Nothing saved: the address changed since `base_revision_number`, was replaced by an edit, or is synced from another system or redacted.
  - When: `address_save_result.save_mode` is `stale_address`, `blocked_superseded_historical_address` or `blocked_external_or_compliance`. Not the usual error envelope: the body has `success: false`, `address_save_result` and `message`. Fix: Re-read `address_save_result.current_address`, then save against it. A `blocked_external_or_compliance` address can't be edited at all.
- `422` Validation failed or external Shopify customers are read-only from this API.
  - When: A field has the wrong type, or a US or Canadian state can't be matched. `error.code` is `validation_failed`. Fix: Fix each field named in `error.fields`; its keys are field paths such as `contact.0.phone`.
  - When: The customer comes from Shopify, or is a system customer (`error.code` `validation_error`, with the reason in `error.message`). Fix: Change Shopify customers in Shopify. System customers cannot be changed.

## Notes

- Always use the id in `data` from the answer from now on: after a replacement it is a new id.

## Related

- [List a customer's addresses](https://developer.yoprint.com/reference/customer-addresses/v1-customer-address-index.md): `GET /v1/api/store/{team_slug}/customer/{hash_id}/address`
- [Update a brand profile (same as PUT)](https://developer.yoprint.com/reference/customer-brand-profiles/v1-customer-profile-update-patch.md): `PATCH /v1/api/store/{team_slug}/customer/{hash_id}/profile/{id}`
