# createEmailTemplate mutation


`createEmailTemplate` 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 an e-mail template of the organisation. Call it to add a template of your own. To start
from an existing one, use [`copyEmailTemplate`](/chameleoon-max/mutation/copy-email-template).

#### Permissions

- Requires the `emailTemplate.manage` permission.
- A non-empty `defaultCc` or `defaultBcc` also requires the `email.read` permission, because
  every send copies those addresses. Without it, the call fails with `FORBIDDEN_ROLE`.

#### Errors

- `VALIDATION` with reason `BUILT_IN_CODE` (field `code`) when the code is a built-in
  template's.
- `CONFLICT` with reason `CODE_TAKEN` when the organisation already has a template with the
  code.
- `VALIDATION` with reason `JSON_ONE_VARIANT` (field `language`) when a `JSON` template has a
  variant of a language. A `JSON` template has exactly one variant, the all-languages one, and
  its languages are its translations.
- `VALIDATION` with reason `UNKNOWN_LANGUAGE` when a language is not in the locales catalogue.
- `VALIDATION` with reason `TEMPLATE_ERROR`, `DESIGN_INVALID`, `DESIGN_TOO_LARGE` or
  `SYNTAX_MISMATCH` when a variant's content is refused (see [`EmailTemplateVariant`](/chameleoon-max/type/email-template-variant)).

## Arguments

- `input`: [`CreateEmailTemplateInput!`](/chameleoon-max/type/create-email-template-input) · required

## Returns

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

## Example

**Mutation**

```graphql
mutation createEmailTemplate($input: CreateEmailTemplateInput!) {
  createEmailTemplate(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",
    "name": "example",
    "resourceKind": "NONE",
    "variants": [
      {
        "subject": "example"
      }
    ]
  }
}
```

**Response**

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