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

# Generate Template Code

> Use this endpoint to convert a structured sequence of template blocks into Pongo2 template code. The response returns the generated code together with the data fields it references, so you can preview a template before saving it.



## OpenAPI

````yaml en/openapi/v3-current/reporter.yaml post /v1/templates/generate-code
openapi: 3.1.0
info:
  title: Reporter
  description: ''
  version: 2.1.2
servers:
  - url: https://reporter.sandbox.lerian.net
security: []
tags: []
paths:
  /v1/templates/generate-code:
    post:
      tags:
        - Templates API
      summary: Generate Template Code
      description: >-
        Use this endpoint to convert a structured sequence of template blocks
        into Pongo2 template code. The response returns the generated code
        together with the data fields it references, so you can preview a
        template before saving it.
      parameters:
        - $ref: '#/components/parameters/Authorization'
        - $ref: '#/components/parameters/XOrganizationId'
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                blocks:
                  type: array
                  description: The ordered sequence of template blocks to convert.
                  items:
                    type: object
                format:
                  type: string
                  description: >-
                    The output format the template targets (for example, HTML,
                    CSV, or TXT).
            example:
              format: TXT
              blocks:
                - type: loop
                  collection: accounts
                  iterator: account
                  children:
                    - type: field
                      field: account.name
        required: true
      responses:
        '200':
          description: The generated template code and the fields it references.
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    description: The generated Pongo2 template code.
                  mappedFields:
                    type: object
                    description: The data-source fields referenced by the generated code.
              example:
                code: '{% for account in accounts %}{{ account.name }}{% endfor %}'
                mappedFields:
                  accounts:
                    - name
          headers: {}
        '400':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Error0016:
                  $ref: '#/components/examples/Error0016'
                Error0017:
                  $ref: '#/components/examples/Error0017'
          headers: {}
      security: []
components:
  parameters:
    Authorization:
      name: Authorization
      in: header
      description: >-
        The authorization token in the 'Bearer <token>' format.  


        **Important:** This header is required if your environment has Access
        Manager enabled. For more information, refer to the [Access
        Manager](/en/access-manager) documentation.
      required: false
      schema:
        type: string
    XOrganizationId:
      name: X-Organization-id
      in: header
      description: The unique identifier of the Organization associated with the request.
      required: true
      example: 019c96a0-0a98-7287-9a31-786e0809c769
      schema:
        type: string
  schemas:
    Error:
      type: object
      properties:
        code:
          type: string
          description: A unique, stable identifier for the error.
        title:
          type: string
          description: A brief summary of the issue.
        message:
          type: string
          description: Detailed guidance for resolving the error.
      description: Response message error.
      required:
        - code
        - title
        - message
  examples:
    Error0016:
      summary: Missing Fields in Request
      value:
        code: TPL-0016
        title: Missing Fields in Request
        message: >-
          Your request is missing one or more required fields. Please refer to
          the documentation to ensure all necessary fields are included in your
          request.
    Error0017:
      summary: Bad Request
      value:
        code: TPL-0017
        title: Bad Request
        message: >-
          The server could not understand the request due to malformed syntax.
          Please check the listed fields and try again.

````