# addInvoiceTag mutation


`addInvoiceTag` 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 invoice. 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 invoice reaches a state people in MAX
should see on it, such as paid or sent to the customer.

[`syncInvoice`](/chameleoon-max/mutation/sync-invoice) never changes the invoice's tags, so a tag stays through every later
sync.

When the tag belongs to a group that holds one tag at a time (`TagGroup.exclusive`), the
invoice's other tag of that group is taken off: to move the invoice from one state 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 `invoice.read` and `invoice.write` permissions.

#### Repeated calls

A tag the invoice 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 the invoice's register
  (`TagAgenda`: issued, advance or received invoices).
- `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
- `tag`: `String!` · required

## Returns

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

## Example

**Mutation**

```graphql
mutation addInvoiceTag($ref: InvoiceRefInput!, $tag: String!) {
  addInvoiceTag(ref: $ref, tag: $tag) {
    invoice {
      id
      direction
      kind
      status
      failureReason
      source
    }
    changed
  }
}
```

**Variables**

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

**Response**

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