# copyEmailTemplate mutation


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

Copies a built-in or organisation template to a new code. Call it to change a built-in
template, which cannot be written directly.

- The copy keeps the original's variants, texts and defaults. A copy of a `JSON` template keeps
  its one all-languages variant.
- Requires the `emailTemplate.manage` permission.
- `NOT_FOUND` (field `from`) when the template to copy does not exist.
- `VALIDATION` with reason `BUILT_IN_CODE` (field `code`) when the new code is a built-in
  template's. `CONFLICT` with reason `CODE_TAKEN` when the organisation already has it.

## Arguments

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

## Returns

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

## Example

**Mutation**

```graphql
mutation copyEmailTemplate($input: CopyEmailTemplateInput!) {
  copyEmailTemplate(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": {
    "from": "example",
    "code": "example",
    "name": "example",
    "subject": "example"
  }
}
```

**Response**

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