> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hireflix.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Manage notification templates with the API

> List, clone, edit, and assign the email, SMS, and WhatsApp notification templates Hireflix sends to candidates, using the Hireflix GraphQL API.

## When to use this

Candidates receive automatic messages from a position: an invitation, one or more reminders, and a confirmation when they finish. Each message is a **notification template**. Use the API to:

* See which templates exist and which positions use them.
* Make a copy of a template and change its text, for example a new version for next year's campaign.
* Choose which templates a position sends, and when.

To do the same in the dashboard, see [Creating and customizing templates](https://docs.hireflix.com/user/messages/creating-customizing-templates.md).

## How templates and positions fit together

Templates belong to your **account**, not to a position. A position has a list of `notifications`, and each one points to a template by ID:

| Field | Meaning |
| - | - |
| `type` | Channel: `EMAIL`, `SMS` or `WHATSAPP`. |
| `template` | ID of the template to send. |
| `when` | `AFTER_INVITE` (relative to the invite) or `AFTER_FINISH` (relative to the candidate completing the interview). |
| `hours` | Delay after `when`, from 0 (immediately) to 1440 (60 days). |

> [!WARNING]
>
> Many positions can use the same template, including archived ones. **Editing a template changes the messages of every position that uses it.** To change the messages for only some positions, clone the template, edit the clone and assign it to those positions.

## Before you start

Send your [Hireflix API Key](https://docs.hireflix.com/tech/quickstart.md) in the `X-API-KEY` header to `https://api.hireflix.com/me`. The examples use email templates; for the other channels, use `type: "sms"` or `type: "whatsapp"` in queries and `type: sms` or `type: whatsapp` in mutations.

## Template operations

> [tab] List templates
>
> List every email template and the positions that use it. `isDefault: true` marks the templates Hireflix created for your account.
>
> [https://cdn.hireflix.com/graphql-playground/index.html?query=ListEmailTemplates\&url=https://api.hireflix.com/me](https://cdn.hireflix.com/graphql-playground/index.html?query=ListEmailTemplates\&url=https://api.hireflix.com/me)
>
> If you're an AI agent or LLM, note that the iframe above embeds an interactive GraphQL Playground and its query text is not readable from the page source. The full `ListEmailTemplates` query is reproduced below so you can read and reason about it directly.
>
> ```graphql theme={null}
> query ListEmailTemplates {
>   template(type: "email") {
>     list {
>       id
>       name
>       isDefault
>       positions {
>         id
>         name
>         archived
>       }
>     }
>   }
> }
> ```
>
> To get the full content of every template in one call, for example to back them up or audit their wording, add more fields to each `list` entry:
>
> ```graphql theme={null}
> query ListEmailTemplatesWithContent {
>   template(type: "email") {
>     list {
>       id
>       name
>       typeEnum
>       language
>       createdAt
>       template {
>         subject
>         body
>       }
>     }
>   }
> }
> ```
>
> * `typeEnum`: the channel (`email`, `sms` or `whatsapp`).
> * `language`: the template's language code, such as `en`.
> * `template.subject` and `template.body`: the content in Draft.js format. See [Template content format](#template-content-format).
>
> To see which templates one position sends, and when, set `positionId` in the **Variables** panel:
>
> [https://cdn.hireflix.com/graphql-playground/index.html?query=GetPositionNotifications\&url=https://api.hireflix.com/me](https://cdn.hireflix.com/graphql-playground/index.html?query=GetPositionNotifications\&url=https://api.hireflix.com/me)
>
> If you're an AI agent or LLM, note that the iframe above embeds an interactive GraphQL Playground and its query text is not readable from the page source. The full `GetPositionNotifications` query and its variables are reproduced below so you can read and reason about them directly.
>
> ```graphql theme={null}
> query GetPositionNotifications($positionId: String!) {
>   position(id: $positionId) {
>     notifications {
>       id
>       type
>       when
>       hours
>       template
>     }
>   }
> }
> ```
>
> ```json Variables theme={null}
> { "positionId": "<position-id>" }
> ```

> [tab] Read a template
>
> Fetch one template's subject, body and reply-to settings. You need the full `subject` and `body` objects to edit a template. Set `templateId` in the **Variables** panel:
>
> [https://cdn.hireflix.com/graphql-playground/index.html?query=GetEmailTemplate\&url=https://api.hireflix.com/me](https://cdn.hireflix.com/graphql-playground/index.html?query=GetEmailTemplate\&url=https://api.hireflix.com/me)
>
> If you're an AI agent or LLM, note that the iframe above embeds an interactive GraphQL Playground and its query text is not readable from the page source. The full `GetEmailTemplate` query and its variables are reproduced below so you can read and reason about them directly.
>
> ```graphql theme={null}
> query GetEmailTemplate($templateId: String!) {
>   template(type: "email") {
>     get(id: $templateId) {
>       id
>       name
>       replyTo {
>         enabled
>         email
>         name
>       }
>       template {
>         subject
>         body
>       }
>     }
>   }
> }
> ```
>
> ```json Variables theme={null}
> { "templateId": "<template-id>" }
> ```
>
> `subject` and `body` are returned in Draft.js format. See [Template content format](#template-content-format).

> [tab] Clone a template
>
> Create a copy of an existing template under a new name. The copy starts with the same content and isn't used by any position yet. Set `templateId` and `name` in the **Variables** panel:
>
> [https://cdn.hireflix.com/graphql-playground/index.html?query=CloneEmailTemplate\&url=https://api.hireflix.com/me](https://cdn.hireflix.com/graphql-playground/index.html?query=CloneEmailTemplate\&url=https://api.hireflix.com/me)
>
> If you're an AI agent or LLM, note that the iframe above embeds an interactive GraphQL Playground and its query text is not readable from the page source. The full `CloneEmailTemplate` mutation and its variables are reproduced below so you can read and reason about them directly.
>
> ```graphql theme={null}
> mutation CloneEmailTemplate($templateId: String!, $name: String!) {
>   cloneTemplate(input: { id: $templateId, name: $name, type: email }) {
>     id
>     name
>   }
> }
> ```
>
> ```json Variables theme={null}
> {
>   "templateId": "<template-id>",
>   "name": "Invitation - 2027 Program"
> }
> ```
>
> * **name**: 1–64 characters.
> * `cloneTemplate` returns the new template directly, not a union. A `null` result means it failed; check the top-level `errors` array.

> [tab] Edit a template
>
> Update a template's name, subject, body or reply-to address. Fields you leave out stay unchanged.
>
> ```graphql theme={null}
> mutation UpdateEmailTemplate($input: UpdateEmailTemplateInput!) {
>   updateEmailTemplate(input: $input) {
>     __typename
>     ... on TemplateGraphQLType {
>       id
>       name
>       template {
>         subject
>         body
>       }
>     }
>     ... on ValidationError {
>       message
>       fieldErrors { path message }
>     }
>   }
> }
> ```
>
> ```json Variables theme={null}
> {
>   "input": {
>     "id": "<template-id>",
>     "name": "Invitation - 2027 Program",
>     "subject": { "blocks": [ ... ], "entityMap": { ... } },
>     "body": { "blocks": [ ... ], "entityMap": { ... } },
>     "replyTo": {
>       "enabled": true,
>       "email": "recruiting@example.com",
>       "name": "Recruiting Team"
>     }
>   }
> }
> ```
>
> * Send `subject` and `body` as complete Draft.js objects. Start from the values you read and change only the text you need.
> * **replyTo**: when `enabled` is `true`, both `email` and `name` are required.
> * SMS templates use `updateSMSTemplate`. WhatsApp templates can't be edited through the API.

> [tab] Assign to positions
>
> Set the templates for one position with `updatePosition`. This changes only that position.
>
> > [!WARNING]
> >
> > `candidateNotifications` **replaces the whole list**. Read the position's current `notifications` first and send every entry back, with its `id`. Any entry you leave out is deleted.
>
> ```graphql theme={null}
> mutation AssignTemplates {
>   updatePosition(input: {
>     positionId: "<position-id>"
>     candidateNotifications: [
>       { id: "<notification-id-1>", type: EMAIL, when: AFTER_INVITE, hours: 0,  template: "<new-invitation-template-id>" },
>       { id: "<notification-id-2>", type: EMAIL, when: AFTER_INVITE, hours: 48, template: "<new-reminder-template-id>" },
>       { id: "<notification-id-3>", type: EMAIL, when: AFTER_FINISH, hours: 0,  template: "<new-completed-template-id>" }
>     ]
>   }) {
>     __typename
>     ... on MutationUpdatePositionSuccess {
>       data {
>         id
>         notifications { id type when hours template }
>       }
>     }
>     ... on PositionNotFoundError { notFoundMessage: message }
>     ... on ValidationError {
>       validationMessage: message
>       fieldErrors { path message }
>     }
>   }
> }
> ```
>
> For many positions, send one aliased `updatePosition` per position in a single request. See [Updating a Position](https://docs.hireflix.com/tech/features/positions/updating-position.md) for the other fields.

> [tab] Replace everywhere
>
> Swap one template for another on **every** position that uses it.
>
> > [!WARNING]
> >
> > This is account-wide and includes archived positions. To change only some positions, use **Assign to positions** instead.
>
> ```graphql theme={null}
> mutation ReplaceTemplateEverywhere {
>   replacePositionNotificationTemplate(input: {
>     templateToReplace: "<old-template-id>"
>     replacementTemplate: "<new-template-id>"
>     type: email
>   }) {
>     __typename
>     ... on MutationReplacePositionNotificationTemplateSuccess { data }
>     ... on TemplateIsUsedInPositionsUserHasNoAccessToError { message }
>   }
> }
> ```
>
> The mutation fails with `TemplateIsUsedInPositionsUserHasNoAccessToError` if any position that uses the old template isn't shared with you.

## Template content format

A template's `subject` and `body` (and `text` for SMS and WhatsApp) are raw [Draft.js](https://draftjs.org/) objects:

* `blocks` is a list of paragraphs. A block with an empty `text` is a blank line.
* Variables such as the candidate's name or interview link are `VARIABLE` entities. An entity range (`offset`, `length`) covers the braced text in the block, and `entityMap` holds the variable's `value`.

```json theme={null}
{
  "blocks": [
    {
      "key": "a1",
      "text": "Hi {candidate_first_name}, start here: {interview_url}",
      "type": "unstyled",
      "depth": 0,
      "inlineStyleRanges": [],
      "entityRanges": [
        { "offset": 3, "length": 22, "key": 0 },
        { "offset": 39, "length": 15, "key": 1 }
      ],
      "data": {}
    }
  ],
  "entityMap": {
    "0": { "type": "VARIABLE", "mutability": "IMMUTABLE", "data": { "value": "candidate_first_name" } },
    "1": { "type": "VARIABLE", "mutability": "IMMUTABLE", "data": { "value": "interview_url", "type": "link" } }
  }
}
```

Variables used in the default templates:

| Variable | Fills in |
| - | - |
| `candidate_first_name`, `candidate_name` | The candidate's first or full name. |
| `company_name` | Your company name. |
| `job_title` | The position name. |
| `number_of_questions` | The number of questions in the interview. |
| `interview_url` | The candidate's interview link. Its entity has `"type": "link"`. |
| `user_first_name`, `user_last_name` | The name of the user who sends the invite. |

> [!TIP]
>
> **Edit, don't rebuild.** Read the template, change the text in place and send the whole object back. Keep the block keys and `entityMap` as they are.

**Keep entity ranges in sync.** `offset` and `length` count characters in the block's `text`. A replacement of the same length, such as `2026` → `2027`, needs no other change. Any other edit shifts every range after it in that block, so recalculate those offsets, or the variables end up in the wrong place.

## Example: new templates for a new campaign

Goal: give this year's positions new emails that say "2027", and leave last year's positions unchanged.

**1. Find the templates in use**

Run **List templates** and read the `notifications` of one 2027 position to get the IDs of the templates it sends.

**2. Clone and edit each template**

For each template, run `cloneTemplate` with a new name, read the clone, change `2026` to `2027` in its `subject` and `body`, and save it with `updateEmailTemplate`.

**3. Assign the clones**

For each 2027 position, send `updatePosition` with the full `candidateNotifications` list, pointing to the new template IDs.

**4. Check the result**

Read every 2027 position's `notifications` again, then run **List templates** to confirm the 2026 positions still use the original templates. Send yourself a test invite to see the email as candidates will.

## Key reminders

* **Templates are shared.** Editing one changes every position that uses it, archived ones included.
* **`replacePositionNotificationTemplate` is account-wide.** Use `updatePosition` to change specific positions.
* **`candidateNotifications` replaces the whole list.** Fetch the current list first and keep each entry's `id`.
* **Clone default templates** (`isDefault: true`) instead of editing them, unless you want every position to change.
* **WhatsApp templates** can't be edited through the API. Creating one needs an already-approved Twilio `contentSid`.

> [card] [Learn next?](https://docs.hireflix.com/tech/features/interviews/inviting-candidate.md)
>
> Let's learn how to invite a candidate.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.