# updateSalesOrderAddresses mutation


`updateSalesOrderAddresses` is a GraphQL mutation of the Chameleoon MAX API. Send it as `POST https://max-api.chameleoon.sk/api/v1/graphql` with your API key, see [Chameleoon MAX](/chameleoon-max).

Updates the order's billing address, delivery address or collection point with the external
source's current values. Call it when one of them changes in the external source after the
order was placed, and send only what changed.

MAX takes the new address unless a user changed that address in MAX since, or the parcel is
already packed or shipped. In those cases MAX keeps its own address and opens an exception on
the order, with your address in the exception's data, for a user in MAX to resolve.

| Code | Blocks the order | When |
| --- | --- | --- |
| `SHOP_ADDRESS_CONFLICT` | When the parcel goes to that address | A user changed the address in MAX. |
| `SHOP_ADDRESS_CHANGED_AFTER_PACKING` | When the parcel goes to that address | The parcel is packed. |
| `SHOP_ADDRESS_CHANGED_AFTER_SHIPPING` | No | The parcel has shipped. |

The result says what happened to each address you sent.

#### Permissions

Requires the `order.write` and `order.read` permissions.

#### Repeated calls

A repeat changes nothing and returns `UNCHANGED`.

#### Errors

- `CONFLICT` when the order is cancelled or merged.
- `NOT_FOUND` when the order does not exist or your API key cannot see it.
- `VALIDATION` when an address has no street, city, postal code or country, when a field is
  too long, or when a collection point has no code or comes with a delivery address.
- `FORBIDDEN_ROLE` (`partner.write`) when a new address must be added to the customer's address
  book.

#### Good to know

- An erased customer's order keeps its addresses and returns `UNCHANGED`.

> An error whose path runs below this field does not mean the call failed: the addresses were
> processed, so do not retry. See [`Mutation`](/chameleoon-max/mutations).

## Arguments

- `ref`: [`SalesOrderRefInput!`](/chameleoon-max/type/sales-order-ref-input) · required
- `input`: [`SalesOrderAddressesInput!`](/chameleoon-max/type/sales-order-addresses-input) · required

## Returns

[`SalesOrderAddressesResult!`](/chameleoon-max/type/sales-order-addresses-result)

## Example

**Mutation**

```graphql
mutation updateSalesOrderAddresses($ref: SalesOrderRefInput!, $input: SalesOrderAddressesInput!) {
  updateSalesOrderAddresses(ref: $ref, input: $input) {
    salesOrder {
      id
      number
      status
      legalEntityId
      source
      externalId
    }
    billingAddress
    deliveryAddress
  }
}
```

**Variables**

```json
{
  "ref": {
    "id": "00000000-0000-4000-8000-000000000001"
  },
  "input": {}
}
```

**Response**

```json
{
  "data": {
    "updateSalesOrderAddresses": {
      "salesOrder": {
        "id": "00000000-0000-4000-8000-000000000001",
        "number": "example",
        "status": "DRAFT",
        "legalEntityId": "00000000-0000-4000-8000-000000000001",
        "source": "example",
        "externalId": "example"
      },
      "billingAddress": "APPLIED",
      "deliveryAddress": "APPLIED"
    }
  }
}
```

Values are illustrative: replace IDs and codes with your own before you send the call.
