# setEmailTemplateVariant mutation


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

Creates or replaces one variant of the template. Call it with the `version` you read to change
a subject or body, or to add a language.

#### Permissions

Requires the `emailTemplate.manage` permission.

#### HTML templates

- If `htmlBody` is omitted, the variant keeps its own HTML. When `textBody` is omitted too, it
  also keeps its own text.
- A new variant without `htmlBody` copies the HTML of the all-languages variant, else the
  `sk` variant, else the first variant.
- A `design` is refused with `VALIDATION` and reason `SYNTAX_MISMATCH`.

#### JSON templates

- Only the all-languages variant can be set. A `language` is refused with `VALIDATION` (field
  `language`) and reason `JSON_ONE_VARIANT`, because its languages are its translations.
- If `design` is omitted, the variant keeps its own design.
- `htmlBody` and `textBody` are refused with `VALIDATION` and reason `SYNTAX_MISMATCH`.

#### Errors

`CONFLICT` with reason `TEMPLATE_CHANGED` when somebody saved the template after you read it.

## Arguments

- `input`: [`SetEmailTemplateVariantInput!`](/chameleoon-max/type/set-email-template-variant-input) · required

## Returns

[`EmailTemplate!`](/chameleoon-max/type/email-template)

## Example

**Mutation**

```graphql
mutation setEmailTemplateVariant($input: SetEmailTemplateVariantInput!) {
  setEmailTemplateVariant(input: $input) {
    id
    code
    name
    builtIn
    resourceKind
    syntax
    variants {
      language
      subject
      htmlBody
      textBody
      design
    }
    languages
    allLanguages
    texts(first: 10) {
      totalCount
    }
    defaultTo
    defaultCc
    defaultBcc
    defaultAttachments
    copiedFrom
    version
  }
}
```

**Variables**

```json
{
  "input": {
    "code": "example",
    "version": 1,
    "subject": "example"
  }
}
```

**Response**

```json
{
  "data": {
    "setEmailTemplateVariant": {
      "id": "00000000-0000-4000-8000-000000000001",
      "code": "example",
      "name": "example",
      "builtIn": true,
      "resourceKind": "NONE",
      "syntax": "HTML",
      "variants": [
        {
          "language": "example",
          "subject": "example",
          "htmlBody": "example",
          "textBody": "example",
          "design": {}
        }
      ],
      "languages": [
        "example"
      ],
      "allLanguages": true,
      "texts": {
        "totalCount": 1
      },
      "defaultTo": "CUSTOMER",
      "defaultCc": [
        "example"
      ],
      "defaultBcc": [
        "example"
      ],
      "defaultAttachments": [
        "ORDER_INVOICE_PDF"
      ],
      "copiedFrom": "example",
      "version": 1
    }
  }
}
```

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