# modifyInvoiceTags mutation


`modifyInvoiceTags` 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 invoice'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 invoice's other tag of that group.
- `toRemove`: every tag on the invoice with the code is taken off, an archived one too. A tag
  the invoice does not have, or a code no tag has, is skipped.
- `clearGroups`: every tag on the invoice in the group is taken off, also when the group is
  archived. Use it when the invoice 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
invoice as it is then. A retry after a lost answer is safe; a retry after another writer moved
the invoice to a different tag of the same group moves it back.

#### Permissions

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

#### Repeated calls

A call that finds the invoice'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 the invoice's register.
- `NOT_FOUND` when the invoice does not exist or your API key cannot see it.

## Arguments

- `ref`: [`InvoiceRefInput!`](/chameleoon-max/type/invoice-ref-input) · required
- `input`: [`InvoiceTagsInput!`](/chameleoon-max/type/invoice-tags-input) · required

## Returns

[`InvoiceTagsResult!`](/chameleoon-max/type/invoice-tags-result)

## Example

**Mutation**

```graphql
mutation modifyInvoiceTags($ref: InvoiceRefInput!, $input: InvoiceTagsInput!) {
  modifyInvoiceTags(ref: $ref, input: $input) {
    invoice {
      id
      direction
      kind
      status
      failureReason
      source
    }
    changed
  }
}
```

**Variables**

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

**Response**

```json
{
  "data": {
    "modifyInvoiceTags": {
      "invoice": {
        "id": "00000000-0000-4000-8000-000000000001",
        "direction": "ISSUED",
        "kind": "INVOICE",
        "status": "PENDING",
        "failureReason": "example",
        "source": "example"
      },
      "changed": true
    }
  }
}
```

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