# Create template account

**Endpoint**

`POST/v2/messages/templates`

**Link**

{% embed url="<https://stagep.tst-apidmndelss.com/openapi/v2.html#/operations/Messages_CreateTemplate>" %}

### **Request**

#### **Headers**

| Key             | Value              | Required |
| --------------- | ------------------ | -------- |
| `Authorization` | `Bearer <JWT>`     | Yes      |
| `Content-Type`  | `application/json` | Yes      |
| `Accept`        | `application/json` | Yes      |

#### **Request Body (JSON)**

| Field          | Type      | Description & Requirements                                                                                                        | Required | Example                      |
| -------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------- | -------- | ---------------------------- |
| **`typeId`**   | `integer` | <p><strong>Template type</strong>:<br>- <code>1</code>: Email<br>- <code>2</code>: SMS<br>- <code>3</code>: Push notification</p> | Yes      | `1`                          |
| **`subject`**  | `string`  | **Email subject line** (required for email templates).                                                                            | Yes      | `"Welcome to Our Platform!"` |
| **`title`**    | `string`  | **Message title/header**.                                                                                                         | Yes      | `"Account Created"`          |
| **`content`**  | `string`  | **Message body** with variable placeholders.                                                                                      | Yes      | `"Hello {{name}}, welcome!"` |
| **`button`**   | `string`  | **Button text** (for email templates).                                                                                            | No       | `"Login Now"`                |
| **`link`**     | `string`  | **Button URL** (for email templates).                                                                                             | No       | `"https://app.example.com"`  |
| **`delay`**    | `string`  | **Delivery delay** after trigger (e.g., "5m", "2h").                                                                              | No       | `"10m"`                      |
| **`showTime`** | `string`  | **Preferred sending time** (24-hour format).                                                                                      | No       | `"09:00"`                    |
| **`triggers`** | `array`   | **Events that trigger this template** (see below).                                                                                | No       | -                            |

**Trigger Object**

| Field         | Type      | Description                                      | Example |
| ------------- | --------- | ------------------------------------------------ | ------- |
| **`eventId`** | `integer` | **ID of the event** that triggers this template. | `101`   |
| **`event`**   | `object`  | **Event details** (optional, see below).         | -       |

**Event Object (optional in request)**

| Field           | Type      | Description                         | Example              |
| --------------- | --------- | ----------------------------------- | -------------------- |
| **`id`**        | `integer` | Event ID.                           | `101`                |
| **`Name`**      | `string`  | Event name.                         | `"customer.created"` |
| **`variables`** | `array`   | Available variables for this event. | -                    |

**Example Request Body (Email Template):**

json

```
{
  "typeId": 1,
  "subject": "Welcome to Acme Payments!",
  "title": "Account Created Successfully",
  "content": "Hello {{customerName}}, your account has been created. Your customer ID is {{customerId}}.",
  "button": "Access Your Account",
  "link": "https://app.acme.com/login",
  "delay": "0s",
  "showTime": "09:00",
  "triggers": [
    {
      "eventId": 101
    }
  ]
}
```

**Example Request Body (SMS Template):**

json

```
{
  "typeId": 2,
  "subject": "",
  "title": "Security Alert",
  "content": "Acme: Login from new device at {{location}}. Contact support if this wasn't you.",
  "delay": "0s",
  "triggers": [
    {
      "eventId": 205
    }
  ]
}
```

***

### **Response (200 OK)**

Returns the newly created template with system-generated fields.

#### **Response Fields**

| Field           | Type      | Description                                  | Example                          |
| --------------- | --------- | -------------------------------------------- | -------------------------------- |
| **`id`**        | `string`  | **System-generated template ID**.            | `"tpl_abc123"`                   |
| **`partnerId`** | `string`  | **Partner ID** that owns the template.       | `"ptn_456def"`                   |
| **`typeId`**    | `integer` | Template type from request.                  | `1`                              |
| **`subject`**   | `string`  | Subject from request.                        | `"Welcome to Acme Payments!"`    |
| **`title`**     | `string`  | Title from request.                          | `"Account Created Successfully"` |
| **`content`**   | `string`  | Content from request.                        | `"Hello {{customerName}}..."`    |
| **`button`**    | `string`  | Button text from request.                    | `"Access Your Account"`          |
| **`link`**      | `string`  | Link URL from request.                       | `"https://app.acme.com/login"`   |
| **`updatedAt`** | `string`  | Creation timestamp (ISO 8601).               | `"2024-05-21T10:30:00Z"`         |
| **`createdAt`** | `string`  | Creation timestamp (ISO 8601).               | `"2024-05-21T10:30:00Z"`         |
| **`deletedAt`** | `string`  | Deletion timestamp (null for new templates). | `null`                           |
| **`delay`**     | `string`  | Delay from request.                          | `"0s"`                           |
| **`isActive`**  | `boolean` | **Active status** (default: `true`).         | `true`                           |
| **`showTime`**  | `string`  | Show time from request.                      | `"09:00"`                        |
| **`triggers`**  | `array`   | **Trigger events** with full event details.  | -                                |

**Example Response:**

json

```
{
  "item": {
    "id": "tpl_abc123",
    "partnerId": "ptn_456def",
    "typeId": 1,
    "subject": "Welcome to Acme Payments!",
    "title": "Account Created Successfully",
    "content": "Hello {{customerName}}, your account has been created. Your customer ID is {{customerId}}.",
    "button": "Access Your Account",
    "link": "https://app.acme.com/login",
    "updatedAt": "2024-05-21T10:30:00Z",
    "createdAt": "2024-05-21T10:30:00Z",
    "deletedAt": null,
    "delay": "0s",
    "isActive": true,
    "showTime": "09:00",
    "triggers": [
      {
        "eventId": 101,
        "templateId": 1,
        "event": {
          "id": 101,
          "Name": "customer.created",
          "variables": [
            {"name": "customerId"},
            {"name": "customerName"},
            {"name": "email"}
          ]
        }
      }
    ]
  }
}
```

***

### **Examples**

#### **Request**

bash

```
curl -X POST 'https://stagep.tst-apidmndelss.com/v2/messages/templates' \
  -H 'Authorization: Bearer eyJhbGci...wNLGA' \
  -H 'Content-Type: application/json' \
  -d '{
    "typeId": 1,
    "subject": "Password Reset Request",
    "title": "Reset Your Password",
    "content": "Hello {{name}}, click the button below to reset your password. This link expires in 1 hour.",
    "button": "Reset Password",
    "link": "https://app.example.com/reset-password?token={{resetToken}}",
    "delay": "0s",
    "triggers": [
      {
        "eventId": 150
      }
    ]
  }'
```

***

### **Error Responses**

1. **Invalid Event ID**:

   json

   ```
   { "error": "Event ID 999 not found" }
   ```
2. **Missing Required Field**:

   json

   ```
   { "error": "subject is required for email templates" }
   ```
3. **Invalid Variable**:

   json

   ```
   { "error": "Variable 'invalidVar' not available for this event" }
   ```

***

### **Notes**

* **Variable Syntax**: Use `{{variableName}}` in content for dynamic values.
* **Template Types**:
  * `1`: Email (requires subject, supports button/link)
  * `2`: SMS (no subject/button/link needed)
  * `3`: Push notification
* **Auto-activation**: New templates are automatically active (`isActive: true`).
* **Event Validation**: Triggers are validated against available system events.

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.delos.financial/messages/create-template-account.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
