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

# Create Template

> Create a new email template with HTML content and design settings using the AutoSend API.

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.autosend.com/v1/templates \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
    "templateName": "Welcome Email",
    "description": "Welcome email for new users",
    "subject": "Welcome to {{companyName}}, {{firstName}}!",
    "previewText": "We are glad to have you on board",
    "emailTemplate": "<h1>Welcome, {{firstName}}!</h1><p>Thanks for joining {{companyName}}.</p>",
    "templateType": "transactional",
    "builderType": "code"
  }'
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.autosend.com/v1/templates"

  headers = {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json"
  }

  payload = {
      "templateName": "Welcome Email",
      "description": "Welcome email for new users",
      "subject": "Welcome to {{companyName}}, {{firstName}}!",
      "previewText": "We are glad to have you on board",
      "emailTemplate": "<h1>Welcome, {{firstName}}!</h1><p>Thanks for joining {{companyName}}.</p>",
      "templateType": "transactional",
      "builderType": "code"
  }

  response = requests.post(url, json=payload, headers=headers)
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  fetch('https://api.autosend.com/v1/templates', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer <token>',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      templateName: 'Welcome Email',
      description: 'Welcome email for new users',
      subject: 'Welcome to {{companyName}}, {{firstName}}!',
      previewText: 'We are glad to have you on board',
      emailTemplate: '<h1>Welcome, {{firstName}}!</h1><p>Thanks for joining {{companyName}}.</p>',
      templateType: 'transactional',
      builderType: 'code'
    })
  })
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));
  ```

  ```php PHP theme={null}
  <?php

  $url = 'https://api.autosend.com/v1/templates';

  $data = [
      'templateName' => 'Welcome Email',
      'description' => 'Welcome email for new users',
      'subject' => 'Welcome to {{companyName}}, {{firstName}}!',
      'previewText' => 'We are glad to have you on board',
      'emailTemplate' => '<h1>Welcome, {{firstName}}!</h1><p>Thanks for joining {{companyName}}.</p>',
      'templateType' => 'transactional',
      'builderType' => 'code'
  ];

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      'Authorization: Bearer <token>',
      'Content-Type: application/json'
  ]);

  $response = curl_exec($ch);
  curl_close($ch);

  echo $response;
  ?>
  ```

  ```go Go theme={null}
  package main

  import (
      "bytes"
      "encoding/json"
      "fmt"
      "net/http"
  )

  func main() {
      url := "https://api.autosend.com/v1/templates"

      payload := map[string]interface{}{
          "templateName":  "Welcome Email",
          "description":   "Welcome email for new users",
          "subject":       "Welcome to {{companyName}}, {{firstName}}!",
          "previewText":   "We are glad to have you on board",
          "emailTemplate": "<h1>Welcome, {{firstName}}!</h1><p>Thanks for joining {{companyName}}.</p>",
          "templateType":  "transactional",
          "builderType":   "code",
      }

      jsonData, _ := json.Marshal(payload)

      req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
      req.Header.Set("Authorization", "Bearer <token>")
      req.Header.Set("Content-Type", "application/json")

      client := &http.Client{}
      resp, err := client.Do(req)
      if err != nil {
          fmt.Println("Error:", err)
          return
      }
      defer resp.Body.Close()

      fmt.Println("Response Status:", resp.Status)
  }
  ```

  ```java Java theme={null}
  import java.io.OutputStream;
  import java.net.HttpURLConnection;
  import java.net.URL;
  import java.nio.charset.StandardCharsets;

  public class CreateTemplate {
      public static void main(String[] args) {
          try {
              URL url = new URL("https://api.autosend.com/v1/templates");
              HttpURLConnection con = (HttpURLConnection) url.openConnection();

              con.setRequestMethod("POST");
              con.setRequestProperty("Authorization", "Bearer <token>");
              con.setRequestProperty("Content-Type", "application/json");
              con.setDoOutput(true);

              String jsonInputString = "{\n" +
                  "  \"templateName\": \"Welcome Email\",\n" +
                  "  \"description\": \"Welcome email for new users\",\n" +
                  "  \"subject\": \"Welcome to {{companyName}}, {{firstName}}!\",\n" +
                  "  \"previewText\": \"We are glad to have you on board\",\n" +
                  "  \"emailTemplate\": \"<h1>Welcome, {{firstName}}!</h1><p>Thanks for joining {{companyName}}.</p>\",\n" +
                  "  \"templateType\": \"transactional\",\n" +
                  "  \"builderType\": \"code\"\n" +
                  "}";

              try (OutputStream os = con.getOutputStream()) {
                  byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
                  os.write(input, 0, input.length);
              }

              int status = con.getResponseCode();
              System.out.println("Response Status: " + status);

          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  ```

  ```ruby Ruby theme={null}
  require 'net/http'
  require 'json'
  require 'uri'

  uri = URI('https://api.autosend.com/v1/templates')

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Post.new(uri.path)
  request['Authorization'] = 'Bearer <token>'
  request['Content-Type'] = 'application/json'

  request.body = {
    templateName: 'Welcome Email',
    description: 'Welcome email for new users',
    subject: 'Welcome to {{companyName}}, {{firstName}}!',
    previewText: 'We are glad to have you on board',
    emailTemplate: '<h1>Welcome, {{firstName}}!</h1><p>Thanks for joining {{companyName}}.</p>',
    templateType: 'transactional',
    builderType: 'code'
  }.to_json

  response = http.request(request)
  puts response.body
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "success": true,
    "data": {
      "templateId": "A-abc123def456ghi789jk",
      "templateName": "Welcome Email",
      "description": "Welcome email for new users",
      "subject": "Welcome to {{companyName}}, {{firstName}}!",
      "previewText": "We are glad to have you on board",
      "emailTemplate": "<h1>Welcome, {{firstName}}!</h1><p>Thanks for joining {{companyName}}.</p>",
      "templateType": "transactional",
      "builderType": "code",
      "createdAt": "2026-03-17T10:30:00.000Z",
      "updatedAt": "2026-03-17T10:30:00.000Z"
    }
  }
  ```
</ResponseExample>

### Authorizations

<ParamField path="Authorizations" type="string | header" required>
  Bearer authentication header of the form Bearer `<token>`, where `<token>` is your auth token.
</ParamField>

### Body

Template data for creating a new email template

<ParamField path="templateName" type="string" required>
  Name of the template (max 90 characters).

  Maximum length: `90`

  Example: `"Welcome Email"`
</ParamField>

<ParamField path="subject" type="string" required>
  Email subject line (max 988 characters). Supports Handlebars template variables.

  Maximum length: `988`

  Example: `"Welcome to {{companyName}}, {{firstName}}!"`
</ParamField>

<ParamField path="description" type="string">
  Short description of the template (max 140 characters).

  Maximum length: `140`

  Example: `"Welcome email for new users"`
</ParamField>

<ParamField path="previewText" type="string">
  Email preview text / preheader (max 140 characters). This text is shown in email clients before the email is opened.

  Maximum length: `140`

  Example: `"We are glad to have you on board"`
</ParamField>

<ParamField path="emailTemplate" type="string">
  HTML content of the email template. Supports Handlebars syntax for dynamic variables.

  **Handlebars Template Variables:**

  Use Handlebars syntax for template variables in your HTML. Variables are wrapped in double curly braces: `{{variableName}}`.

  Example:

  ```html theme={null}
  <h1>Welcome, {{firstName}}!</h1>
  <p>Thanks for joining {{companyName}}.</p>
  ```

  Provide the values for these variables in the `dynamicData` field when sending emails using this template.
</ParamField>

<ParamField path="templateType" type="string">
  Type of the template.

  Allowed values: `transactional`, `marketing`

  Default: `"transactional"`

  Example: `"transactional"`
</ParamField>

<ParamField path="builderType" type="string">
  Builder type used to create the template.

  Allowed values: `code`, `visual`

  Default: `"code"`

  Example: `"code"`
</ParamField>

<ParamField path="dynamicVariables" type="object">
  Dynamic variables configuration for the template.

  Example:

  ```json theme={null}
  {
    "firstName": "string",
    "companyName": "string"
  }
  ```
</ParamField>

<ParamField path="senderId" type="string">
  ID of the sender to associate with this template. The sender must belong to the same project.

  Example: `"60d5ec49f1b2c72d9c8b4567"`
</ParamField>

### Response

<span className="text-sm">Template created successfully</span>

<ResponseField name="success" type="boolean">
  Indicates if the request was successful

  Example: `true`
</ResponseField>

<ResponseField name="data" type="object">
  The created template object

  <Expandable title="child attributes">
    <ResponseField name="data.templateId" type="string">
      Unique template identifier

      Example: `"A-abc123def456ghi789jk"`
    </ResponseField>

    <ResponseField name="data.templateName" type="string">
      Name of the template

      Example: `"Welcome Email"`
    </ResponseField>

    <ResponseField name="data.description" type="string">
      Template description

      Example: `"Welcome email for new users"`
    </ResponseField>

    <ResponseField name="data.subject" type="string">
      Email subject line

      Example: `"Welcome to {{companyName}}, {{firstName}}!"`
    </ResponseField>

    <ResponseField name="data.previewText" type="string">
      Email preview text

      Example: `"We are glad to have you on board"`
    </ResponseField>

    <ResponseField name="data.emailTemplate" type="string">
      HTML content of the template
    </ResponseField>

    <ResponseField name="data.templateType" type="string">
      Type of template

      Example: `"transactional"`
    </ResponseField>

    <ResponseField name="data.builderType" type="string">
      Builder type used

      Example: `"code"`
    </ResponseField>

    <ResponseField name="data.createdAt" type="string">
      ISO 8601 timestamp of creation

      Example: `"2026-03-17T10:30:00.000Z"`
    </ResponseField>

    <ResponseField name="data.updatedAt" type="string">
      ISO 8601 timestamp of last update

      Example: `"2026-03-17T10:30:00.000Z"`
    </ResponseField>
  </Expandable>
</ResponseField>


## OpenAPI

````yaml POST /templates
openapi: 3.1.0
info:
  title: AutoSend API
  description: AutoSend REST API for managing email templates
  version: 1.0.0
servers:
  - url: https://api.autosend.com/v1
security:
  - bearerAuth: []
paths:
  /templates:
    post:
      summary: Create Template
      description: >-
        Creates a new email template. Templates can be either transactional or
        marketing type, and built using code (HTML) or the visual builder.
components: {}

````