# addSalesOrderTag mutation


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

Puts a tag on the order. Name the tag by its code, as [`tags`](/chameleoon-max/query/tags) lists it: a code stays
when a user renames the tag in MAX. Call it when the order reaches a state in the external
source that people in MAX should see on it, such as a shop's own order status.

When the tag belongs to a group that holds one tag at a time (`TagGroup.exclusive`), the order's
other tag of that group is taken off: to move the order from one status tag to the next, add
the next.

MAX does not create tags: a user creates them in MAX first. An archived tag cannot be added.

#### Permissions

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

#### Repeated calls

A tag the order already has changes nothing and returns `changed: false`.

#### Errors

- `VALIDATION` with reason `TAG_NOT_FOUND` when no live tag in MAX has this code (an archived
  one does not count).
- `VALIDATION` when the code is blank, or the 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
- `tag`: `String!` · required

## Returns

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

## Example

**Mutation**

```graphql
mutation addSalesOrderTag($ref: SalesOrderRefInput!, $tag: String!) {
  addSalesOrderTag(ref: $ref, tag: $tag) {
    salesOrder {
      id
      number
      status
      legalEntityId
      source
      externalId
    }
    changed
  }
}
```

**Variables**

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

**Response**

```json
{
  "data": {
    "addSalesOrderTag": {
      "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.
