Skip to main content
Sitecore Documentation
  • Learn
  • Downloads
  • Changelog
  • Roadmap
PersonalizeCloud Portal
Sitecore Personalize developer documentation
  • Developing with Sitecore Personalize
    • Base URL
    • Response codes
        • Create a template
        • Retrieve templates
        • Retrieve a template
        • Update a template
        • Retrieve revisions
        • Retrieve a revision
        • Preview templates
        • Preview template code
  1. REST API Template
  1. Sitecore Personalize developer documentation
  2. REST APIs

Create a template

POST /v3/templates

Creates a template.

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

AttributeTypeDescriptionExample(s)
namestringThe name of the template."Alert bar template"
friendlyIdstringThe unique ID of the template.

Only lowercase alphanumeric characters and underscores are allowed.
"alert_bar_template_1"
typestring enum (uppercase)The type of the template.Must be one of:

  • "WEB"
  • "DECISION"
  • "CONDITION"
  • "JS_MODULE"
statusstring enum (uppercase)The current status of the template.Must be one of:

  • "DRAFT"
  • "PUBLISHED"
descriptionstringThe description of the connection."Alert bar web template"
renderbooleanDetermines whether to render a preview of the web template in the Sitecore Personalize app.

Only set this to true if you're confident that your web template can render.

Do not set this to true for more sophisticated web templates that use handlebars loops.
true, false
defaultTemplatebooleanDetermines whether this is a default template.

When you create a template, you must set this value to false.
false
customTemplatebooleanDetermines whether this is a custom template.

When you create a template, you must set this value to true.
true
templateElements

optional
JSON array of JSON objectsCustom 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:

AttributeTypeDescriptionExample(s)
idstring enum (lowercase)The type of code that you include in the template attribute.

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:

  • "html"
  • "css"
  • "js"
  • "freemarker"
templatestringStringified HTML, CSS, JavaScript, or FreeMarker code.

For FreeMarker code, you must at a minimum include an opening and a closing curly bracket {}.
  • HTML: "<div id=\"test\">My test div</div>"
  • CSS: "#test {text-transform: uppercase}"
  • JavaScript: "insertHTMLBefore(\"body\");"
  • FreeMarker: "{}"

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

"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 or update it.

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": "{}"
    }
    ]
}'
{
    "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
}
If you have suggestions for improving this article, let us know!

Documentation Assistant

This assistant uses AI to generate responses based on Sitecore documentation. While it has access to official sources, answers may be incomplete or inaccurate and should not be considered official advice or support.
Powered by
k
kapa.ai
Protected by reCAPTCHA

© Copyright 2026, Sitecore A/S or a Sitecore affiliated company.
All rights reserved.

Privacy policySitecore Trust CenterTerms of use