> ## 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.

# Compile template

> Compiles an MJML template with provided data, returning the rendered HTML.
When `subject` and/or `subject_preview` are provided, they are rendered
through the same Liquid engine used at send time and returned alongside
the HTML so callers do not need to run a separate Liquid pass to preview
the subject line. Useful for previewing templates before saving.




## OpenAPI

````yaml /openapi.json post /api/templates.compile
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
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.compile:
    post:
      summary: Compile template
      description: >
        Compiles an MJML template with provided data, returning the rendered
        HTML.

        When `subject` and/or `subject_preview` are provided, they are rendered

        through the same Liquid engine used at send time and returned alongside

        the HTML so callers do not need to run a separate Liquid pass to preview

        the subject line. Useful for previewing templates before saving.
      operationId: compileTemplate
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CompileTemplateRequest'
      responses:
        '200':
          description: Template compiled successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CompileTemplateResponse'
        '400':
          description: Bad request - compilation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: 'Compilation failed: Invalid MJML syntax'
        '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'
      security:
        - BearerAuth: []
components:
  schemas:
    CompileTemplateRequest:
      type: object
      required:
        - workspace_id
        - message_id
        - visual_editor_tree
      properties:
        workspace_id:
          type: string
          description: The ID of the workspace
          example: ws_1234567890
        message_id:
          type: string
          description: Unique message ID for tracking
          example: msg_abc123
        visual_editor_tree:
          type: object
          description: MJML visual editor tree structure (must have type 'mjml')
          additionalProperties: true
        subject:
          type: string
          description: >
            Optional email subject. When provided, it is rendered through the
            same

            Liquid engine the send path uses (with `test_data`) and the rendered

            result is returned as `subject` in the response. Liquid processing
            is

            skipped when `preserve_liquid` is true, `channel` is `web`, or

            `test_data` is empty.
          example: Hi {{ contact.first_name }}
        subject_preview:
          type: string
          description: >
            Optional inbox preview text (the snippet shown after the subject in

            most clients). Rendered through Liquid like `subject` and returned
            as

            `subject_preview` in the response.
          example: Welcome {{ contact.first_name }}
        test_data:
          type: object
          description: Data to use for Liquid templating
          additionalProperties: true
          example:
            user_name: John Doe
            action_url: https://example.com/action
        tracking_settings:
          $ref: '#/components/schemas/TrackingSettings'
        channel:
          type: string
          enum:
            - email
            - web
          description: Channel filter for block visibility
    CompileTemplateResponse:
      type: object
      properties:
        success:
          type: boolean
          description: Whether compilation was successful
        mjml:
          type: string
          description: Generated MJML markup
        html:
          type: string
          description: Compiled HTML output
        subject:
          type: string
          description: |
            Rendered email subject. Present only when the request included a
            non-empty `subject`. Returned on both success and error paths so the
            caller can display the rendered subject alongside any compilation
            error.
          example: Hi Pierre
        subject_preview:
          type: string
          description: >
            Rendered inbox preview text. Present only when the request included
            a

            non-empty `subject_preview`. Returned on both success and error
            paths.
          example: Welcome Pierre
        error:
          type: object
          description: MJML compilation error details, if any
          properties:
            message:
              type: string
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Error message
      required:
        - error
    TrackingSettings:
      type: object
      properties:
        enable_tracking:
          type: boolean
          description: Whether to enable click/open tracking
        endpoint:
          type: string
          description: API endpoint for tracking redirects
        utm_source:
          type: string
          description: UTM source parameter
        utm_medium:
          type: string
          description: UTM medium parameter
        utm_campaign:
          type: string
          description: UTM campaign parameter
        utm_content:
          type: string
          description: UTM content parameter
        utm_term:
          type: string
          description: UTM term parameter
        workspace_id:
          type: string
          description: Workspace ID for tracking
        message_id:
          type: string
          description: Message ID for tracking
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: API token for authentication

````