# updateSalesOrderDetails mutation


`updateSalesOrderDetails` 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 notes, contact, carrier and payment method with the external source's
current values. Call it when any of them changes in the external source after the order was
placed, and send only what changed.

For addresses, use [`updateSalesOrderAddresses`](/chameleoon-max/mutation/update-sales-order-addresses).

- **Notes and contact** belong to the external source. MAX writes them as sent, except on
  cancelled and merged orders.
- **Carrier** (the route your delivery method maps to) and **payment method**: MAX writes them
  unless a user changed the value in MAX since, the parcel is packed (for the payment method:
  a label is made), money is already committed under the old payment method, or your value
  maps to nothing in MAX.

When MAX does not write a carrier or payment method, it keeps its own value and opens a
`SHOP_CHANGE_*` exception on the order, with your value in the exception's data. The
exception blocks the order, except for a warning after shipping and a refusal (`REFUSED`).

The result says what happened to each group 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 a text is too long, an item note has no `externalId`, or you send more
  than 500 item notes.

#### Good to know

- An erased customer's order keeps its notes and contact as they are.

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

Costs 1 point plus 1 per item note, plus its selection.

## Arguments

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

## Returns

[`SalesOrderDetailsResult!`](/chameleoon-max/type/sales-order-details-result)

## Example

**Mutation**

```graphql
mutation updateSalesOrderDetails($ref: SalesOrderRefInput!, $input: SalesOrderDetailsInput!) {
  updateSalesOrderDetails(ref: $ref, input: $input) {
    salesOrder {
      id
      number
      status
      legalEntityId
      source
      externalId
    }
    note
    internalNote
    contact
    itemNotes
    unknownItemExternalIds
    carrier
    paymentMethod
  }
}
```

**Variables**

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

**Response**

```json
{
  "data": {
    "updateSalesOrderDetails": {
      "salesOrder": {
        "id": "00000000-0000-4000-8000-000000000001",
        "number": "example",
        "status": "DRAFT",
        "legalEntityId": "00000000-0000-4000-8000-000000000001",
        "source": "example",
        "externalId": "example"
      },
      "note": "APPLIED",
      "internalNote": "APPLIED",
      "contact": "APPLIED",
      "itemNotes": "APPLIED",
      "unknownItemExternalIds": [
        "example"
      ],
      "carrier": "APPLIED",
      "paymentMethod": "APPLIED"
    }
  }
}
```

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