# Create template

- Operation ID: `create-template`
- HTTP method: `POST`
- Path: `/template-backend/template`
- [Human-readable API reference](https://hub.synerise.com/api-reference/campaigns#tag/Templates/operation/create-template)

## Self-contained OpenAPI method

The fenced document below contains this method's documentation and all of its local references. It is self-contained; no category or master specification fetch is required.

```yaml
openapi: 3.0.0
info:
  title: Synerise Public API
  version: 1.9.1
paths:
  /template-backend/template:
    post:
      summary: Create template
      operationId: create-template
      tags:
        - Templates
      description: |
        Create a new template.

        ---

        **API consumer:** <a href="/api-reference/authorization?tag=Authorization&amp;operationId=userLogin" target="_blank" rel="noopener">Synerise User</a>

        **User role permission required:** `templates: create`
      requestBody:
        description: Template to create
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - content
                - directory
                - source
              properties:
                name:
                  type: string
                  description: Name of the template
                  default: null
                  nullable: true
                type:
                  type: string
                  description: Template type
                  example: EMAIL
                  default: null
                  nullable: true
                  enum:
                    - SMS
                    - MOBILE_PUSH
                    - WEB_PUSH
                    - DYNAMIC_CONTENT
                    - LANDING_PAGE
                    - EMAIL
                    - SOCIAL_MEDIA
                    - IN_APP
                    - null
                subtype:
                  type: string
                  description: |
                    Template subtype. Currently accepted subtypes are
                    - `BANNER` (can be used with mobile push)
                    - `TOP_BAR`, `BOTTOM_BAR`, `MODAL` (can be used with in app notifications)
                    - `null`.
                  example: BANNER
                  nullable: true
                  default: null
                  enum:
                    - BANNER
                    - TOP_BAR
                    - BOTTOM_BAR
                    - MODAL
                    - null
                contentType:
                  type: string
                  enum:
                    - TEMPLATE
                    - BLOCK
                  example: TEMPLATE
                directory:
                  type: string
                  format: uuid
                  description: UUID of the directory where the template will be saved
                  example: e0326a2d-7697-4ae9-b490-31f97041adcb
                content:
                  type: string
                  description: |
                    Template content as a **stringified, escaped object**.

                    This includes HTML, JS, CSS, and other data, depending on the template type.
                  example: '{"json":"","html":"<p>some text</p>","css":"p {\n    font-weight: bold\n}","js":"console.log(\"test\")","raw":"<html><head><style type=\"text/css\">p {\n    font-weight: bold\n}</style></head><body><p>some text</p></body></html>","source":2}'
                source:
                  type: integer
                  format: int64
                  description: |
                    Information about used editor. Currently accepted builder are
                    - `LACK_OF_INFORMATION` = 0
                    - `BEE_FREE_EDITOR` = 1
                    - `DYNAMIC_CONTENT_CODE_EDITOR` = 2
                    - `MAIL_EDITOR` = 3
                    - `SMS_EDITOR` = 4
                    - `WEB_PUSH_EDITOR` = 5
                    - `MOBILE_SIMPLE_PUSH_VISUAL_EDITOR` = 6
                    - `MOBILE_SILENT_PUSH_CODE_EDITOR` = 7
                    - `FACEBOOK_POST_EDITOR` = 13
                    - `IMPORT_FROM_ZIP` = 14
                    - `IMPORT_FROM_URL` = 15
                    - `GRAPES_EDITOR` = 16
                    - `VISUAL_BUILDER` = 17
                    - `LANDING_PAGE_ADVANCED_DRAG_AND_DROP` = 18
                    - `WEB_BEE_FREE_EDITOR` = 19
                    - `MOBILE_SIMPLE_PUSH_CODE_EDITOR` = 20
                    - `LANDING_PAGE_CODE_EDITOR` = 21
                    - `LANDING_PAGE_BASIC_DRAG_AND_DROP` = 22
                includeSafeArea:
                  type: boolean
                  description: Define if in_app template should include safe area
                  default: false
                  nullable: true
                hidden:
                  type: boolean
                  description: Define if the template is hidden
                  default: false
                  nullable: true
                temporal:
                  type: boolean
                  description: Define if template can be deleted if was not used in any place
                  default: false
                  nullable: true
      responses:
        "200":
          description: Created template
          content:
            application/json:
              schema:
                type: object
                required:
                  - id
                  - hashId
                  - businessProfileId
                  - name
                  - templateContent
                  - type
                  - subtype
                  - thumbnailUrl
                  - directory
                  - createdAt
                  - updatedAt
                  - parsedData
                  - parsedContent
                  - functionType
                  - author
                  - status
                  - source
                properties:
                  id:
                    type: integer
                    format: int64
                    description: Template ID
                  hashId:
                    type: string
                    description: Template hashId (UUID)
                    example: e0326a2d-7697-4ae9-b490-31f97041adcb
                  businessProfileId:
                    type: integer
                    description: Workspace ID
                    example: 594
                  name:
                    type: string
                    description: Name of the template
                    default: null
                    nullable: true
                  templateContent:
                    type: string
                    description: |
                      Template content as a **stringified, escaped object**.

                      This includes HTML, JS, CSS, and other data, depending on the template type.
                    example: '{"json":"","html":"<p>some text</p>","css":"p {\n    font-weight: bold\n}","js":"console.log(\"test\")","raw":"<html><head><style type=\"text/css\">p {\n    font-weight: bold\n}</style></head><body><p>some text</p></body></html>","source":2}'
                  type:
                    type: string
                    description: Template type
                    example: EMAIL
                    default: null
                    nullable: true
                    enum:
                      - SMS
                      - MOBILE_PUSH
                      - WEB_PUSH
                      - DYNAMIC_CONTENT
                      - LANDING_PAGE
                      - EMAIL
                      - SOCIAL_MEDIA
                      - IN_APP
                      - null
                  subtype:
                    type: string
                    description: |
                      Template subtype. Currently accepted subtypes are
                      - `BANNER` (can be used with mobile push)
                      - `TOP_BAR`, `BOTTOM_BAR`, `MODAL` (can be used with in app notifications)
                      - `null`.
                    example: BANNER
                    nullable: true
                    default: null
                    enum:
                      - BANNER
                      - TOP_BAR
                      - BOTTOM_BAR
                      - MODAL
                      - null
                  contentType:
                    type: string
                    enum:
                      - TEMPLATE
                      - BLOCK
                    example: TEMPLATE
                  thumbnailUrl:
                    type: string
                    description: URL of the template's thumbnail
                    example: https://foo.bar
                  directory:
                    type: object
                    description: Details of the directory that includes this template
                    required:
                      - hashId
                      - name
                      - readOnly
                      - createdAt
                      - default
                      - type
                    properties:
                      hashId:
                        type: string
                        format: uuid
                        example: e0326a2d-7697-4ae9-b490-31f97041adcb
                        description: Directory hashId (UUID)
                      name:
                        type: string
                        description: Name of the directory
                      readOnly:
                        type: boolean
                        example: true
                        description: "`true` when the directory is read-only"
                      createdAt:
                        type: string
                        description: Time of creation
                        format: date-time
                        example: 2019-03-21T12:31:26Z
                      type:
                        nullable: true
                        type: string
                        description: Directory type
                        example: EMAIL
                      contentType:
                        type: string
                        enum:
                          - TEMPLATE
                          - BLOCK
                        example: TEMPLATE
                      default:
                        type: boolean
                        example: true
                        description: When `true`, this template belongs to one of the default folders
                      predefined:
                        type: boolean
                        example: true
                  createdAt:
                    type: string
                    description: Time of creation
                    format: date-time
                    example: 2019-03-21T12:31:26Z
                  updatedAt:
                    type: string
                    description: Time of last update
                    example: 2019-03-21T12:31:26Z
                  parsedData:
                    type: object
                    properties:
                      links:
                        type: object
                  parsedContent:
                    type: string
                  functionType:
                    type: string
                    description: Function type
                    example: Password Change
                  author:
                    type: integer
                    format: int64
                    description: Author ID
                    example: 123
                  status:
                    type: string
                    description: Approval status of the template. If approvals are disabled, the status is null.
                    nullable: true
                    enum:
                      - DRAFT
                      - REVIEW
                      - APPROVED
                      - REJECTED
                  source:
                    type: integer
                    format: int64
                    description: |
                      Information about used editor. Currently accepted builder are
                      - `LACK_OF_INFORMATION` = 0
                      - `BEE_FREE_EDITOR` = 1
                      - `DYNAMIC_CONTENT_CODE_EDITOR` = 2
                      - `MAIL_EDITOR` = 3
                      - `SMS_EDITOR` = 4
                      - `WEB_PUSH_EDITOR` = 5
                      - `MOBILE_SIMPLE_PUSH_VISUAL_EDITOR` = 6
                      - `MOBILE_SILENT_PUSH_CODE_EDITOR` = 7
                      - `FACEBOOK_POST_EDITOR` = 13
                      - `IMPORT_FROM_ZIP` = 14
                      - `IMPORT_FROM_URL` = 15
                      - `GRAPES_EDITOR` = 16
                      - `VISUAL_BUILDER` = 17
                      - `LANDING_PAGE_ADVANCED_DRAG_AND_DROP` = 18
                      - `WEB_BEE_FREE_EDITOR` = 19
                      - `MOBILE_SIMPLE_PUSH_CODE_EDITOR` = 20
                      - `LANDING_PAGE_CODE_EDITOR` = 21
                      - `LANDING_PAGE_BASIC_DRAG_AND_DROP` = 22
                  includeSafeArea:
                    type: boolean
                    description: Define if in_app template should include safe area
                    default: false
                    nullable: true
      security:
        - JWT: []
      x-snr-doc-urls:
        - /api-reference/campaigns#tag/Templates/operation/create-template
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request POST \
              --url https://api.synerise.com/template-backend/template \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
              --header 'content-type: application/json' \
              --data '{"name":null,"type":"EMAIL","subtype":"BANNER","contentType":"TEMPLATE","directory":"e0326a2d-7697-4ae9-b490-31f97041adcb","content":"{\"json\":\"\",\"html\":\"<p>some text</p>\",\"css\":\"p {\\n    font-weight: bold\\n}\",\"js\":\"console.log(\\\"test\\\")\",\"raw\":\"<html><head><style type=\\\"text/css\\\">p {\\n    font-weight: bold\\n}</style></head><body><p>some text</p></body></html>\",\"source\":2}","source":0,"includeSafeArea":false,"hidden":false,"temporal":false}'
        - lang: Python
          label: Python
          source: |-
            import http.client

            conn = http.client.HTTPSConnection("api.synerise.com")

            payload = "{\"name\":null,\"type\":\"EMAIL\",\"subtype\":\"BANNER\",\"contentType\":\"TEMPLATE\",\"directory\":\"e0326a2d-7697-4ae9-b490-31f97041adcb\",\"content\":\"{\\\"json\\\":\\\"\\\",\\\"html\\\":\\\"<p>some text</p>\\\",\\\"css\\\":\\\"p {\\\\n    font-weight: bold\\\\n}\\\",\\\"js\\\":\\\"console.log(\\\\\\\"test\\\\\\\")\\\",\\\"raw\\\":\\\"<html><head><style type=\\\\\\\"text/css\\\\\\\">p {\\\\n    font-weight: bold\\\\n}</style></head><body><p>some text</p></body></html>\\\",\\\"source\\\":2}\",\"source\":0,\"includeSafeArea\":false,\"hidden\":false,\"temporal\":false}"

            headers = {
                'Authorization': "Bearer REPLACE_BEARER_TOKEN",
                'content-type': "application/json"
                }

            conn.request("POST", "/template-backend/template", payload, headers)

            res = conn.getresponse()
            data = res.read()

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = JSON.stringify({
              "name": null,
              "type": "EMAIL",
              "subtype": "BANNER",
              "contentType": "TEMPLATE",
              "directory": "e0326a2d-7697-4ae9-b490-31f97041adcb",
              "content": "{\"json\":\"\",\"html\":\"<p>some text</p>\",\"css\":\"p {\\n    font-weight: bold\\n}\",\"js\":\"console.log(\\\"test\\\")\",\"raw\":\"<html><head><style type=\\\"text/css\\\">p {\\n    font-weight: bold\\n}</style></head><body><p>some text</p></body></html>\",\"source\":2}",
              "source": 0,
              "includeSafeArea": false,
              "hidden": false,
              "temporal": false
            });

            const xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function () {
              if (this.readyState === this.DONE) {
                console.log(this.responseText);
              }
            });

            xhr.open("POST", "https://api.synerise.com/template-backend/template");
            xhr.setRequestHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN");
            xhr.setRequestHeader("content-type", "application/json");

            xhr.send(data);
        - lang: Node.js
          label: Node.js
          source: |-
            const http = require("https");

            const options = {
              "method": "POST",
              "hostname": "api.synerise.com",
              "port": null,
              "path": "/template-backend/template",
              "headers": {
                "Authorization": "Bearer REPLACE_BEARER_TOKEN",
                "content-type": "application/json"
              }
            };

            const req = http.request(options, function (res) {
              const chunks = [];

              res.on("data", function (chunk) {
                chunks.push(chunk);
              });

              res.on("end", function () {
                const body = Buffer.concat(chunks);
                console.log(body.toString());
              });
            });

            req.write(JSON.stringify({
              name: null,
              type: 'EMAIL',
              subtype: 'BANNER',
              contentType: 'TEMPLATE',
              directory: 'e0326a2d-7697-4ae9-b490-31f97041adcb',
              content: '{"json":"","html":"<p>some text</p>","css":"p {\n    font-weight: bold\n}","js":"console.log(\"test\")","raw":"<html><head><style type=\"text/css\">p {\n    font-weight: bold\n}</style></head><body><p>some text</p></body></html>","source":2}',
              source: 0,
              includeSafeArea: false,
              hidden: false,
              temporal: false
            }));
            req.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

            $request = new HttpRequest();
            $request->setUrl('https://api.synerise.com/template-backend/template');
            $request->setMethod(HTTP_METH_POST);

            $request->setHeaders([
              'Authorization' => 'Bearer REPLACE_BEARER_TOKEN',
              'content-type' => 'application/json'
            ]);

            $request->setBody('{"name":null,"type":"EMAIL","subtype":"BANNER","contentType":"TEMPLATE","directory":"e0326a2d-7697-4ae9-b490-31f97041adcb","content":"{\\"json\\":\\"\\",\\"html\\":\\"<p>some text</p>\\",\\"css\\":\\"p {\\\\n    font-weight: bold\\\\n}\\",\\"js\\":\\"console.log(\\\\\\"test\\\\\\")\\",\\"raw\\":\\"<html><head><style type=\\\\\\"text/css\\\\\\">p {\\\\n    font-weight: bold\\\\n}</style></head><body><p>some text</p></body></html>\\",\\"source\\":2}","source":0,"includeSafeArea":false,"hidden":false,"temporal":false}');

            try {
              $response = $request->send();

              echo $response->getBody();
            } catch (HttpException $ex) {
              echo $ex;
            }
        - lang: Java
          label: Java
          source: |-
            HttpResponse<String> response = Unirest.post("https://api.synerise.com/template-backend/template")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .header("content-type", "application/json")
              .body("{\"name\":null,\"type\":\"EMAIL\",\"subtype\":\"BANNER\",\"contentType\":\"TEMPLATE\",\"directory\":\"e0326a2d-7697-4ae9-b490-31f97041adcb\",\"content\":\"{\\\"json\\\":\\\"\\\",\\\"html\\\":\\\"<p>some text</p>\\\",\\\"css\\\":\\\"p {\\\\n    font-weight: bold\\\\n}\\\",\\\"js\\\":\\\"console.log(\\\\\\\"test\\\\\\\")\\\",\\\"raw\\\":\\\"<html><head><style type=\\\\\\\"text/css\\\\\\\">p {\\\\n    font-weight: bold\\\\n}</style></head><body><p>some text</p></body></html>\\\",\\\"source\\\":2}\",\"source\":0,\"includeSafeArea\":false,\"hidden\":false,\"temporal\":false}")
              .asString();
servers:
  - description: Microsoft Azure EU
    url: https://api.synerise.com
  - description: Microsoft Azure USA
    url: https://api.azu.synerise.com
  - description: Google Cloud Platform
    url: https://api.geb.synerise.com
tags:
  - name: Templates
components:
  securitySchemes:
    JWT:
      type: http
      scheme: bearer
      description: |-
        JWT Bearer token. The header looks like this: `Bearer {JWT}`

        Remember to include the space between 'Bearer' and the token.

        Generate a token via the **Authorization** endpoints.
```
