---
title: "Create a template"
slug: "create-a-template"
abstract: "Describes how to create a web template or decision template using the Sitecore Personalize Template REST API."
---
# Create a template

`POST /v3/templates`

Creates a template.

At a minimum, you must provide the following required attributes in the request body:

| Attribute | Type | Description | Example(s) |
| --- | --- | --- | --- |
| `name` | string | The name of the template. | `"Alert bar template"` |
| `friendlyId` | string | The unique ID of the template.<br><br>Only lowercase alphanumeric characters and underscores are allowed. | `"alert_bar_template_1"` |
| `type` | string enum (uppercase) | The type of the template. | Must be one of:<br><br><ul><li>`"WEB"`</li><li>`"DECISION"`</li><li>`"CONDITION"`</li><li>`"JS_MODULE"`</li></ul> |
| `status` | string enum (uppercase) | The current status of the template. | Must be one of:<br><br><ul><li>`"DRAFT"`</li><li>`"PUBLISHED"`</li></ul> |
| `description` | string | The description of the connection. | `"Alert bar web template"` |
| `render` | boolean | Determines whether to render a preview of the web template in the Sitecore Personalize app.<br><br>Only set this to `true` if you're confident that your web template can render.<br><br>Do not set this to `true` for more sophisticated web templates that use handlebars loops. | `true, false` |
| `defaultTemplate` | boolean | Determines whether this is a default template.<br><br>When you create a template, you must set this value to `false`. | `false` |
| `customTemplate` | boolean | Determines whether this is a custom template.<br><br>When you create a template, you must set this value to `true`. | `true` |
| `templateElements`<br><br>optional | JSON array of JSON objects | Custom HTML, CSS, JavaScript, and FreeMarker codes that define the template. | `"mys3cr3tstr1ingforauth1!x"` |

The optional `templateElements` array of objects lets you include HTML, CSS, JavaScript, and FreeMarker codes in your templates. For the objects in `templateElements`, use the following attributes:

| Attribute | Type | Description | Example(s) |
| --- | --- | --- | --- |
| `id` | string enum (lowercase) | The type of code that you include in the `template` attribute.<br><br>For example, to include CSS code in the template, set this value to `"css"`, then specify the custom CSS code in the `template` attribute. | Must be one of:<br><br><ul><li>`"html"`</li><li>`"css"`</li><li>`"js"`</li><li>`"freemarker"`</li></ul> |
| `template` | string | Stringified HTML, CSS, JavaScript, or FreeMarker code.<br><br>For FreeMarker code, you must at a minimum include an opening and a closing curly bracket `{}`. | <ul><li>HTML: `"<div id=\"test\">My test div</div>"`</li><li>CSS: `"#test {text-transform: uppercase}"`</li><li>JavaScript: `"insertHTMLBefore(\"body\");"`</li><li>FreeMarker: `"{}"`</li></ul> |

Here's an example of the `templateElements` array of objects:

```json
"templateElements": [
  {
    "id": "html",
    "template": "<div id=\"test\">My test div</div>"
  },
  {
    "id": "css",
    "template": "#test {text-transform: uppercase}"
  },
  {
    "id": "js",
    "template": "insertHTMLBefore(\"body\");\n\nconst testDiv = document.querySelector(\"#test\");\ntestDiv.insertAdjacentHTML(\"afterbegin\", \"<p>Hello from JavaScript</p>\")"
  },
  {
    "id": "freemarker",
    "template": "{}"
  }
]

```

In the response, the `ref` key contains the template reference.

You use the template reference to interact with a specific template, for example, to [retrieve](https://doc.sitecore.com/personalize/en/developers/api/rest-apis/template-rest-api/retrieve-a-template.html "Retrieve a template") or [update](https://doc.sitecore.com/personalize/en/developers/api/rest-apis/template-rest-api/update-a-template.html "Update a template") it.

```curl
curl -X POST '<baseURL>/v3/templates' \
-H 'Authorization: Bearer <accessToken>' \
-H 'Accept: application/json' \
--data-raw '
{
    "name": "Alert bar template",
    "friendlyId": "alert_bar_template_1",
    "type": "WEB",
    "status": "DRAFT",
    "description": "Alert bar template WEB",
    "render": false,
    "defaultTemplate": false,
    "customTemplate": true,
    "templateElements": [
    {
        "id": "html",
        "template": "<div id=\"test\">My test div</div>"
    },
    {
        "id": "css",
        "template": "#test {text-transform: uppercase}"
    },
    {
        "id": "js",
        "template": "insertHTMLBefore(\"body\");\n\nconst testDiv = document.querySelector(\"#test\");\ntestDiv.insertAdjacentHTML(\"afterbegin\", \"<p>Hello from JavaScript</p>\")"
    },
    {
        "id": "freemarker",
        "template": "{}"
    }
    ]
}'

```

```json
{
    "clientKey": "pqsPERS3lw12v5a9rrHPW1c4hET73GxQ",
    "href": "<baseURL>/v3/templates/340ced1b-c9b7-43f0-9eec-2b9f0b7693fa",
    "ref": "340ced1b-c9b7-43f0-9eec-2b9f0b7693fa",
    "name": "Alert bar template",
    "description": "Alert bar template WEB",
    "modifiedByRef": "zwxCA58jwLzfeU2mNGgalCpoJzNVYOJl@clients",
    "modifiedAt": "2026-07-12T10:`56:46`.53994Z",
    "revision": 1,
    "archived": false,
    "friendlyId": "alert_bar_template_1",
    "type": "WEB",
    "status": "DRAFT",
    "templateElements": [
        {
            "id": "html",
            "template": "<div id=\"test\">My test div</div>"
        },
        {
            "id": "css",
            "template": "#test {text-transform: uppercase}"
        },
        {
            "id": "js",
            "template": "insertHTMLBefore(\"body\");\n\nconst testDiv = document.querySelector(\"#test\");\ntestDiv.insertAdjacentHTML(\"afterbegin\", \"<p>Hello from JavaScript</p>\")"
        },
        {
            "id": "freemarker",
            "template": "{}"
        }
    ],
    "render": false,
    "defaultTemplate": false,
    "tags": [],
    "customTemplate": true
}

```