# Create directory

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

## 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/directory:
    post:
      tags:
        - Template directories
      summary: Create directory
      operationId: create-directory
      description: |
        Create a new directory for templates. A directory can store only one type of templates.

        ---

        **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: Directory to create
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - type
                - name
              properties:
                name:
                  type: string
                  description: Name of the directory
                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
                readOnly:
                  type: boolean
                  description: Define if the directory is read-only
                  default: false
                contentType:
                  type: string
                  enum:
                    - TEMPLATE
                    - BLOCK
                  example: TEMPLATE
      responses:
        "200":
          description: Created directory
          content:
            application/json:
              schema:
                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
      security:
        - JWT: []
      x-snr-doc-urls:
        - /api-reference/campaigns#tag/Template-directories/operation/create-directory
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request POST \
              --url https://api.synerise.com/template-backend/directory \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
              --header 'content-type: application/json' \
              --data '{"name":"string","type":"EMAIL","readOnly":false,"contentType":"TEMPLATE"}'
        - lang: Python
          label: Python
          source: |-
            import http.client

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

            payload = "{\"name\":\"string\",\"type\":\"EMAIL\",\"readOnly\":false,\"contentType\":\"TEMPLATE\"}"

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

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

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

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = JSON.stringify({
              "name": "string",
              "type": "EMAIL",
              "readOnly": false,
              "contentType": "TEMPLATE"
            });

            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/directory");
            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/directory",
              "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: 'string', type: 'EMAIL', readOnly: false, contentType: 'TEMPLATE'}));
            req.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

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

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

            $request->setBody('{"name":"string","type":"EMAIL","readOnly":false,"contentType":"TEMPLATE"}');

            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/directory")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .header("content-type", "application/json")
              .body("{\"name\":\"string\",\"type\":\"EMAIL\",\"readOnly\":false,\"contentType\":\"TEMPLATE\"}")
              .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: Template directories
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.
```
