---
title: "テンプレートを作成する"
slug: "create-a-template"
abstract: "Sitecore PersonalizeテンプレートREST APIを使ってウェブテンプレートまたは意思決定テンプレートを作成する方法を説明しています。"
---
# テンプレートを作成する

POST /v3/templates

テンプレートを作成します。

最低限、リクエスト文に以下の必要な属性を記載する必要があります:

属性

種類

概要

例

name

ストリング

テンプレートの名前です。

"Alert bar template"

friendlyId

ストリング

テンプレートのユニークなIDです。  
  
小文字の英数字文字とアンダースコアのみが許可されています。

"alert\_bar\_template\_1"

type

文字列エヌム(大文字)

テンプレートの種類。

以下のいずれかでなければなりません:  
  

-   "WEB"
-   "DECISION"
-   "CONDITION"
-   "JS\_MODULE"

status

文字列エヌム(大文字)

テンプレートの現在の状況。

以下のいずれかでなければなりません:  
  

-   "DRAFT"
-   "PUBLISHED"

description

ストリング

そのつながりの説明。

"Alert bar web template"

render

ブール値

Sitecore Personalizeアプリでウェブテンプレートのプレビューをレンダリングするかどうかを決定します。  
  
ウェブテンプレートがレンダリングできると自信がある場合にのみ、これを true に設定してください。  
  
ハンドルバーループを使うより高度なウェブテンプレートでは、これを true に設定しないでください。

true, false

defaultTemplate

ブール値

これがデフォルトのテンプレートかどうかを判断します。  
  
テンプレートを作成する際は、この値を falseに設定しなければなりません。

false

customTemplate

ブール値

これがカスタムテンプレートかどうかを判断します。  
  
テンプレートを作成する際は、この値を trueに設定しなければなりません。

true

templateElements  
  
任意

JSON JSONオブジェクトの配列

テンプレートを定義するカスタムHTML、CSS、JavaScript、FreeMarkerコード。

"mys3cr3tstr1ingforauth1!x"

オプションのオブジェクト配列templateElementsでは、テンプレート内にHTML、CSS、JavaScript、FreeMarkerのコードを組み込むことができます。 templateElementsのオブジェクトについては、以下の属性を使用します。

属性

種類

概要

例

id

文字列エナック(小文字)

template属性に含まれるコードの種類です。  
  
例えば、テンプレートにCSSコードを含めるには、この値を "css"に設定し、 template 属性でカスタムCSSコードを指定します。

以下のいずれかでなければなりません:  
  

-   "html"
-   "css"
-   "js"
-   "freemarker"

template

ストリング

ストリング化されたHTML、CSS、JavaScript、またはFreeMarkerコード。  
  
FreeMarkerコードでは、最低限開頭と閉じるカーリーブラケット {}を含める必要があります。

-   HTML: "<div id=\\"test\\">My test div</div>"
-   CSS: "#test {text-transform: uppercase}"
-   JavaScript: "insertHTMLBefore(\\"body\\");"
-   FreeMarker: "{}"

以下はtemplateElementsオブジェクト配列の例です:

"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": "{}"
 }

応答の中のrefキーにはテンプレート参照が含まれています。

例えば、テンプレート参照を使って特定のテンプレートとやり取りしたり、[取得したり更新](https://doc.sitecore.com/personalize/ja/developers/api/rest-apis/template-rest-api/update-a-template.html "Update a template")したりします。[](https://doc.sitecore.com/personalize/ja/developers/api/rest-apis/template-rest-api/retrieve-a-template.html "Retrieve a template")

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
}