# modifySalesOrderTags mutation


`modifySalesOrderTags` 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).

Adds, removes and clears several of the order's tags in one call, all or nothing. Tags and
groups are named by their codes, as [`tags`](/chameleoon-max/query/tags) lists them. Tags you name nowhere stay as
they are.

- `toAdd`: every code must be a live tag in MAX, else nothing changes and the call fails. A tag
  of a group that holds one tag at a time replaces the order's other tag of that group.
- `toRemove`: every tag on the order with the code is taken off, an archived one too. A tag the
  order does not have, or a code no tag has, is skipped.
- `clearGroups`: every tag on the order in the group is taken off, also when the group is
  archived. Use it when the external source moves to a state with no tag in MAX.

At most 50 codes in each list.

The call is not deduplicated by an `Idempotency-Key`: a repeat applies the same change to the
order as it is then. A retry after a lost answer is safe; a retry after another writer moved the
order to a different tag of the same group moves it back.

#### Permissions

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

#### Repeated calls

A call that finds the order's tags already as requested changes nothing and returns
`changed: false`.

#### Errors

- `VALIDATION` with reason `TAG_NOT_FOUND` and field `input.toAdd` when a code in `toAdd` is no live
  tag in MAX. The message lists the codes.
- `VALIDATION` with reason `TAG_GROUP_NOT_FOUND` and field `input.clearGroups` when a code there is no
  tag group in MAX.
- `VALIDATION` when a code is blank, a list is longer than 50, a code is in both `toAdd` and
  `toRemove`, `toAdd` names two tags of one group that holds one at a time or a tag of a group
  in `clearGroups`, or a tag is not used on sales orders.
- `NOT_FOUND` when the order does not exist or your API key cannot see it.

## Arguments

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

## Returns

[`SalesOrderChangeResult!`](/chameleoon-max/type/sales-order-change-result)

## Example

**Mutation**

```graphql
mutation modifySalesOrderTags($ref: SalesOrderRefInput!, $input: SalesOrderTagsInput!) {
  modifySalesOrderTags(ref: $ref, input: $input) {
    salesOrder {
      id
      number
      status
      legalEntityId
      source
      externalId
    }
    changed
  }
}
```

**Variables**

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

**Response**

```json
{
  "data": {
    "modifySalesOrderTags": {
      "salesOrder": {
        "id": "00000000-0000-4000-8000-000000000001",
        "number": "example",
        "status": "DRAFT",
        "legalEntityId": "00000000-0000-4000-8000-000000000001",
        "source": "example",
        "externalId": "example"
      },
      "changed": true
    }
  }
}
```

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