> ## Documentation Index
> Fetch the complete documentation index at: https://docs.notifuse.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a template

> Creates a new template. Each template must have a channel (email or web) with corresponding channel-specific content.



## OpenAPI

````yaml /openapi.json post /api/templates.create
openapi: 3.0.3
info:
  title: Notifuse API
  description: API for Notifuse - a transactional email and newsletter management platform
  version: 1.0.0
  contact:
    name: Notifuse Support
    url: https://www.notifuse.com/support
    email: hello@notifuse.com
  license:
    name: BUSL-1.1
    url: https://github.com/Notifuse/notifuse/blob/main/LICENSE
servers:
  - url: https://{notifuseDomain}
    description: Customer-specific Notifuse API server
    variables:
      notifuseDomain:
        description: Your unique Notifuse domain
        default: demo.notifuse.com
security: []
paths:
  /api/templates.create:
    post:
      summary: Create a template
      description: >-
        Creates a new template. Each template must have a channel (email or web)
        with corresponding channel-specific content.
      operationId: createTemplate
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTemplateRequest'
      responses:
        '201':
          description: Template created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  template:
                    $ref: '#/components/schemas/Template'
        '400':
          description: Bad request - validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                duplicateId:
                  value:
                    error: Template id already exists
                deletedTemplateId:
                  summary: The id belongs to a deleted template
                  value:
                    error: >-
                      Template id belongs to a deleted template and cannot be
                      reused: deleted templates are kept so messages already
                      sent with them can still be displayed. Choose another id
                missingEmail:
                  value:
                    error: email is required for channel 'email'
                invalidId:
                  value:
                    error: >-
                      id must contain only letters, numbers, underscores, and
                      hyphens
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: Failed to create template
      security:
        - BearerAuth: []
components:
  schemas:
    CreateTemplateRequest:
      type: object
      required:
        - workspace_id
        - id
        - name
        - channel
        - category
      properties:
        workspace_id:
          type: string
          description: The ID of the workspace
          example: ws_1234567890
        id:
          type: string
          description: >-
            Unique identifier for the template (alphanumeric, underscores, and
            hyphens only)
          example: welcome_email
          maxLength: 32
          pattern: ^[a-zA-Z0-9_-]+$
        name:
          type: string
          description: Name of the template
          example: Welcome Email
          maxLength: 255
        channel:
          type: string
          enum:
            - email
            - web
          description: Communication channel
          example: email
        email:
          $ref: '#/components/schemas/EmailTemplate'
        web:
          $ref: '#/components/schemas/WebTemplate'
        category:
          type: string
          enum:
            - marketing
            - transactional
            - welcome
            - opt_in
            - unsubscribe
            - bounce
            - blocklist
            - blog
            - other
          description: Template category
          example: transactional
        template_macro_id:
          type: string
          nullable: true
          description: ID of the template macro (layout) to use
        test_data:
          type: object
          additionalProperties: true
          description: Test data for template preview
        settings:
          type: object
          additionalProperties: true
          description: Channel-specific settings
        translations:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/TemplateTranslation'
          description: >-
            Per-language content variants, keyed by language code. Every key
            must be one of the workspace's configured languages.
    Template:
      type: object
      properties:
        id:
          type: string
          description: >-
            Unique identifier for the template (alphanumeric, underscores, and
            hyphens only)
          example: welcome_email
          maxLength: 32
          pattern: ^[a-zA-Z0-9_-]+$
        name:
          type: string
          description: Name of the template
          example: Welcome Email
          maxLength: 255
        version:
          type: integer
          format: int64
          description: Version number of the template
          example: 1
        channel:
          type: string
          enum:
            - email
            - web
          description: Communication channel
          example: email
        email:
          $ref: '#/components/schemas/EmailTemplate'
        web:
          $ref: '#/components/schemas/WebTemplate'
        category:
          type: string
          enum:
            - marketing
            - transactional
            - welcome
            - opt_in
            - unsubscribe
            - bounce
            - blocklist
            - blog
            - other
          description: Template category
          example: transactional
          maxLength: 20
        template_macro_id:
          type: string
          nullable: true
          description: ID of the template macro (layout) to use
        integration_id:
          type: string
          nullable: true
          readOnly: true
          description: >-
            ID of the integration managing this template (e.g., Supabase).
            Server-owned: it is set when the integration creates the template
            and cannot be set or changed through the API.
        test_data:
          type: object
          additionalProperties: true
          description: Test data for template preview
          example:
            user_name: John Doe
            action_url: https://example.com/action
        settings:
          type: object
          additionalProperties: true
          description: Channel-specific third-party settings
        translations:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/TemplateTranslation'
          description: Per-language content variants, keyed by language code
          example:
            fr:
              email:
                subject: Bienvenue
        created_at:
          type: string
          format: date-time
          description: When the template was created
        updated_at:
          type: string
          format: date-time
          description: When the template was last updated
        deleted_at:
          type: string
          format: date-time
          nullable: true
          description: >-
            When the template was deleted, null while it is active. Deleted
            templates no longer appear in `templates.list`, but `templates.get`
            still returns them, because messages already sent are rendered from
            them.
      required:
        - id
        - name
        - channel
        - category
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Error message
      required:
        - error
    EmailTemplate:
      type: object
      properties:
        editor_mode:
          type: string
          enum:
            - visual
            - code
          default: visual
          description: >-
            Which editor the email is written in. `visual` stores the
            drag-and-drop block tree in `visual_editor_tree`; `code` stores raw
            MJML in `mjml_source`. The mode is set when the template is created
            and cannot be changed afterwards: an update in the other mode is
            refused with a 400. To switch, create a new template in the other
            mode.
        mjml_source:
          type: string
          description: >-
            Raw MJML source (supports Liquid templating). Required when
            `editor_mode` is `code`, ignored otherwise.
          example: >-
            <mjml><mj-body><mj-section><mj-column><mj-text>Hello {{
            contact.first_name
            }}</mj-text></mj-column></mj-section></mj-body></mjml>
        sender_id:
          type: string
          description: ID of the sender configuration to use
          example: sender_123
        reply_to:
          type: string
          format: email
          description: Reply-To email address
          example: support@example.com
        subject:
          type: string
          description: Email subject line (supports Liquid templating)
          example: Welcome, {{user_name}}!
        subject_preview:
          type: string
          nullable: true
          description: Preview text shown in email clients
          example: Get started with your account
        compiled_preview:
          type: string
          description: Compiled HTML preview of the email
        visual_editor_tree:
          type: object
          description: >-
            MJML visual editor tree structure. Required when `editor_mode` is
            `visual` (the default), ignored in `code` mode.
          example:
            type: mjml
            children: []
        text:
          type: string
          nullable: true
          description: Plain text version of the email
      required:
        - subject
        - compiled_preview
    WebTemplate:
      type: object
      properties:
        content:
          type: object
          additionalProperties: true
          description: Tiptap JSON content (source of truth for web templates)
        html:
          type: string
          description: Pre-rendered HTML for display
        plain_text:
          type: string
          description: Extracted text for search indexing
      required:
        - content
    TemplateTranslation:
      type: object
      description: >-
        Content for one language. Carries the field matching the template's
        channel: email for an email template, web for a web template.
      properties:
        email:
          $ref: '#/components/schemas/EmailTemplate'
        web:
          $ref: '#/components/schemas/WebTemplate'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: API token for authentication

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.