# previewEmailTemplate query


`previewEmailTemplate` is a GraphQL query 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).

Renders a template as [`sendEmail`](/chameleoon-max/mutation/send-email) would, and stores and queues nothing. Use it to
check a template, or a draft of its parts, before you save or send it.

#### Permissions

- Requires the `email.send` or `emailTemplate.manage` permission.
- The `resource` is read under your API key's permissions exactly as [`sendEmail`](/chameleoon-max/mutation/send-email)
  reads it, and requires the same permissions. This includes the template's default
  attachment: `invoice.read`, and also `price.read` when MAX renders the invoice PDF itself.

#### Errors

- `VALIDATION` with reason `TEMPLATE_ERROR` when a part does not parse or render, as at send.
- `NOT_FOUND` (field `code`) when the template does not exist.
- `NOT_FOUND` or `VALIDATION` (field `resource`) for the `resource`, as in
  [`sendEmail`](/chameleoon-max/mutation/send-email).

#### Good to know

- Without a `resource`, a template written for a kind of record renders fixed, fictitious
  sample data.
- Costs 10 points plus its selection.

## Arguments

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

## Returns

[`EmailPreview!`](/chameleoon-max/type/email-preview)

## Example

**Query**

```graphql
query previewEmailTemplate($input: PreviewEmailTemplateInput!) {
  previewEmailTemplate(input: $input) {
    language
    variantLanguage
    subject
    html
    text
    sampleData
    sender {
      fromName
      fromAddress
    }
    attachments {
      kind
      filename
      notReady
    }
    warnings {
      kind
      part
      name
    }
  }
}
```

**Variables**

```json
{
  "input": {
    "code": "example"
  }
}
```

**Response**

```json
{
  "data": {
    "previewEmailTemplate": {
      "language": "example",
      "variantLanguage": "example",
      "subject": "example",
      "html": "example",
      "text": "example",
      "sampleData": true,
      "sender": {
        "fromName": "example",
        "fromAddress": "example"
      },
      "attachments": [
        {
          "kind": "ORDER_INVOICE_PDF",
          "filename": "example",
          "notReady": true
        }
      ],
      "warnings": [
        {
          "kind": "MISSING_TRANSLATION",
          "part": "example",
          "name": "example"
        }
      ]
    }
  }
}
```

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