# Create a new template

POST https://services.leadconnectorhq.com/emails/builder

Create a new template

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `emails/builder.write`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "2021-07-28"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/emails/builder": {
      "post": {
        "summary": "Create a new template",
        "operationId": "createANewTemplate",
        "description": "Create a new template",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "2021-07-28"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateBuilderDto"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateBuilderSuccesfulResponseDto"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "404": {
            "description": "Not Found"
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "Location-Access": [
              "emails/builder.write"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "CreateBuilderDto": {
        "type": "object",
        "properties": {
          "locationId": {
            "type": "string",
            "example": "ve9EPM428h8vShlRW1KT"
          },
          "title": {
            "type": "string",
            "example": "template title"
          },
          "type": {
            "type": "string",
            "enum": [
              "html",
              "folder",
              "import",
              "builder",
              "blank",
              "ai_template",
              "vibe-editor"
            ]
          },
          "updatedBy": {
            "type": "string",
            "example": "zYy3YOUuHxgomU1uYJty"
          },
          "builderVersion": {
            "type": "string",
            "enum": [
              "1",
              "2"
            ],
            "default": "2"
          },
          "name": {
            "type": "string",
            "example": "Template1"
          },
          "parentId": {
            "type": "string",
            "example": "zYy3YOUuHxgomU1uYJty"
          },
          "templateDataUrl": {
            "type": "string",
            "example": ""
          },
          "importProvider": {
            "type": "string",
            "enum": [
              "mailchimp",
              "active_campaign",
              "kajabi",
              "other",
              "import_with_email_ai"
            ]
          },
          "importURL": {
            "type": "string",
            "example": "https://tplshare.com/fhYJ3Mi"
          },
          "templateSource": {
            "type": "string",
            "example": "template_library"
          },
          "isPlainText": {
            "type": "boolean",
            "example": false
          },
          "subjectLine": {
            "type": "string",
            "example": "Email Subject"
          },
          "fromName": {
            "type": "string",
            "example": "Name of sender"
          },
          "fromEmail": {
            "type": "string",
            "example": "test@abc.com"
          },
          "previewText": {
            "type": "string",
            "example": "preview text"
          }
        },
        "required": [
          "locationId",
          "type",
          "importProvider"
        ],
        "title": "CreateBuilderDto"
      },
      "CreateBuilderSuccesfulResponseDto": {
        "type": "object",
        "properties": {
          "redirect": {
            "type": "string",
            "example": "66e811229245fc098765590",
            "description": "template id"
          },
          "traceId": {
            "type": "string",
            "example": "0c52e980-41f6-4be7-8c4b-e2c5a13dc3c2",
            "description": "trace id"
          }
        },
        "required": [
          "redirect",
          "traceId"
        ],
        "title": "CreateBuilderSuccesfulResponseDto"
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      },
      "UnprocessableDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 422
          },
          "message": {
            "example": [
              "Unprocessable Entity"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "error": {
            "type": "string",
            "example": "Unprocessable Entity"
          }
        },
        "title": "UnprocessableDTO"
      }
    }
  }
}
```

## HighLevel SDK Examples

**Node.js** (`@gohighlevel/api-client`)

```javascript
import HighLevel from '@gohighlevel/api-client';

const ghl = new HighLevel({
  privateIntegrationToken: '<PRIVATE_INTEGRATION_TOKEN>'
});

const body = {
  "locationId": "ve9EPM428h8vShlRW1KT",
  "title": "template title",
  "updatedBy": "zYy3YOUuHxgomU1uYJty",
  "name": "Template1",
  "parentId": "zYy3YOUuHxgomU1uYJty",
  "templateDataUrl": "",
  "importURL": "https://tplshare.com/fhYJ3Mi",
  "templateSource": "template_library",
  "isPlainText": false,
  "subjectLine": "Email Subject",
  "fromName": "Name of sender",
  "fromEmail": "test@abc.com",
  "previewText": "preview text"
};

const response = await ghl.emails.createANewTemplate(body);
console.log(response);
```

**Python** (`gohighlevel-api-client`)

```python
from highlevel import HighLevel

client = HighLevel(
    private_integration_token='<PRIVATE_INTEGRATION_TOKEN>'
)

body = {
    "locationId": "ve9EPM428h8vShlRW1KT",
    "title": "template title",
    "updatedBy": "zYy3YOUuHxgomU1uYJty",
    "name": "Template1",
    "parentId": "zYy3YOUuHxgomU1uYJty",
    "templateDataUrl": "",
    "importURL": "https://tplshare.com/fhYJ3Mi",
    "templateSource": "template_library",
    "isPlainText": false,
    "subjectLine": "Email Subject",
    "fromName": "Name of sender",
    "fromEmail": "test@abc.com",
    "previewText": "preview text"
}

response = await client.emails.create_a_new_template(body=body)
print(response)
```

**PHP** (`gohighlevel/api-client`)

```php
<?php
require_once 'vendor/autoload.php';

use HighLevel\HighLevel;
use HighLevel\HighLevelConfig;

$config = new HighLevelConfig([
    'privateIntegrationToken' => '<PRIVATE_INTEGRATION_TOKEN>'
]);
$ghl = new HighLevel($config);

$body = [
    'locationId' => 've9EPM428h8vShlRW1KT',
    'title' => 'template title',
    'updatedBy' => 'zYy3YOUuHxgomU1uYJty',
    'name' => 'Template1',
    'parentId' => 'zYy3YOUuHxgomU1uYJty',
    'templateDataUrl' => '',
    'importURL' => 'https://tplshare.com/fhYJ3Mi',
    'templateSource' => 'template_library',
    'isPlainText' => false,
    'subjectLine' => 'Email Subject',
    'fromName' => 'Name of sender',
    'fromEmail' => 'test@abc.com',
    'previewText' => 'preview text'
];

$response = $ghl->emails->createANewTemplate($body);
echo json_encode($response, JSON_PRETTY_PRINT);
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/emails/builder' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: 2021-07-28' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "locationId": "ve9EPM428h8vShlRW1KT",
  "title": "template title",
  "updatedBy": "zYy3YOUuHxgomU1uYJty",
  "name": "Template1",
  "parentId": "zYy3YOUuHxgomU1uYJty",
  "templateDataUrl": "",
  "importURL": "https://tplshare.com/fhYJ3Mi",
  "templateSource": "template_library",
  "isPlainText": false,
  "subjectLine": "Email Subject",
  "fromName": "Name of sender",
  "fromEmail": "test@abc.com",
  "previewText": "preview text"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: '2021-07-28',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "locationId": "ve9EPM428h8vShlRW1KT",
      "title": "template title",
      "updatedBy": "zYy3YOUuHxgomU1uYJty",
      "name": "Template1",
      "parentId": "zYy3YOUuHxgomU1uYJty",
      "templateDataUrl": "",
      "importURL": "https://tplshare.com/fhYJ3Mi",
      "templateSource": "template_library",
      "isPlainText": false,
      "subjectLine": "Email Subject",
      "fromName": "Name of sender",
      "fromEmail": "test@abc.com",
      "previewText": "preview text"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/emails/builder', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/emails/builder"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "2021-07-28"
}

payload = {
    "locationId": "ve9EPM428h8vShlRW1KT",
    "title": "template title",
    "updatedBy": "zYy3YOUuHxgomU1uYJty",
    "name": "Template1",
    "parentId": "zYy3YOUuHxgomU1uYJty",
    "templateDataUrl": "",
    "importURL": "https://tplshare.com/fhYJ3Mi",
    "templateSource": "template_library",
    "isPlainText": false,
    "subjectLine": "Email Subject",
    "fromName": "Name of sender",
    "fromEmail": "test@abc.com",
    "previewText": "preview text"
}

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

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/emails/builder',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: 2021-07-28',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "locationId": "ve9EPM428h8vShlRW1KT",
  "title": "template title",
  "updatedBy": "zYy3YOUuHxgomU1uYJty",
  "name": "Template1",
  "parentId": "zYy3YOUuHxgomU1uYJty",
  "templateDataUrl": "",
  "importURL": "https://tplshare.com/fhYJ3Mi",
  "templateSource": "template_library",
  "isPlainText": false,
  "subjectLine": "Email Subject",
  "fromName": "Name of sender",
  "fromEmail": "test@abc.com",
  "previewText": "preview text"
}',
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/emails/builder")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "2021-07-28")
  .header("Content-Type", "application/json")
  .body("{\"locationId\":\"ve9EPM428h8vShlRW1KT\",\"title\":\"template title\",\"updatedBy\":\"zYy3YOUuHxgomU1uYJty\",\"name\":\"Template1\",\"parentId\":\"zYy3YOUuHxgomU1uYJty\",\"templateDataUrl\":\"\",\"importURL\":\"https://tplshare.com/fhYJ3Mi\",\"templateSource\":\"template_library\",\"isPlainText\":false,\"subjectLine\":\"Email Subject\",\"fromName\":\"Name of sender\",\"fromEmail\":\"test@abc.com\",\"previewText\":\"preview text\"}")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
  "strings"
)

func main() {
  url := "https://services.leadconnectorhq.com/emails/builder"
  payload := strings.NewReader(`{
  "locationId": "ve9EPM428h8vShlRW1KT",
  "title": "template title",
  "updatedBy": "zYy3YOUuHxgomU1uYJty",
  "name": "Template1",
  "parentId": "zYy3YOUuHxgomU1uYJty",
  "templateDataUrl": "",
  "importURL": "https://tplshare.com/fhYJ3Mi",
  "templateSource": "template_library",
  "isPlainText": false,
  "subjectLine": "Email Subject",
  "fromName": "Name of sender",
  "fromEmail": "test@abc.com",
  "previewText": "preview text"
}`)
  req, _ := http.NewRequest("POST", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "2021-07-28")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/emails/builder")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "2021-07-28"
request["Content-Type"] = "application/json"
request.body = '{
  "locationId": "ve9EPM428h8vShlRW1KT",
  "title": "template title",
  "updatedBy": "zYy3YOUuHxgomU1uYJty",
  "name": "Template1",
  "parentId": "zYy3YOUuHxgomU1uYJty",
  "templateDataUrl": "",
  "importURL": "https://tplshare.com/fhYJ3Mi",
  "templateSource": "template_library",
  "isPlainText": false,
  "subjectLine": "Email Subject",
  "fromName": "Name of sender",
  "fromEmail": "test@abc.com",
  "previewText": "preview text"
}'

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "2021-07-28"
}

$body = '{
  "locationId": "ve9EPM428h8vShlRW1KT",
  "title": "template title",
  "updatedBy": "zYy3YOUuHxgomU1uYJty",
  "name": "Template1",
  "parentId": "zYy3YOUuHxgomU1uYJty",
  "templateDataUrl": "",
  "importURL": "https://tplshare.com/fhYJ3Mi",
  "templateSource": "template_library",
  "isPlainText": false,
  "subjectLine": "Email Subject",
  "fromName": "Name of sender",
  "fromEmail": "test@abc.com",
  "previewText": "preview text"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/emails/builder' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
