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

# Preview a Target Template

> A `POST` to the `/targets/preview` endpoint processes a Twig template against a chosen
resource and returns the rendered payload. The template is rendered, then parsed as JSON, so
`data.result` is the decoded JSON object (not a string) and `data.context` is the resource
context the template was rendered against.

Provide either an inline `template` or a `target_id` (one is required). If both are sent, the
inline `template` takes precedence.

If the Twig fails to render, or its output is not valid JSON, the request returns `422` with a
captured `error` object (`stage`, `message`, `line`). When the failure is a JSON-parse error
(`stage` is `json`), the raw rendered output is also returned as `rendered_raw` so you can see
what the template produced.



## OpenAPI

````yaml post /v3/targets/preview
openapi: 3.1.0
info:
  title: Omneo
  version: 0.0.1
servers:
  - url: https://api.{tenant}.getomneo.com/api
    variables:
      tenant:
        default: example
security: []
paths:
  /v3/targets/preview:
    post:
      tags:
        - Target
      summary: Preview a Target Template
      description: >-
        A `POST` to the `/targets/preview` endpoint processes a Twig template
        against a chosen

        resource and returns the rendered payload. The template is rendered,
        then parsed as JSON, so

        `data.result` is the decoded JSON object (not a string) and
        `data.context` is the resource

        context the template was rendered against.


        Provide either an inline `template` or a `target_id` (one is required).
        If both are sent, the

        inline `template` takes precedence.


        If the Twig fails to render, or its output is not valid JSON, the
        request returns `422` with a

        captured `error` object (`stage`, `message`, `line`). When the failure
        is a JSON-parse error

        (`stage` is `json`), the raw rendered output is also returned as
        `rendered_raw` so you can see

        what the template produced.
      operationId: target.preview
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PreviewTarget'
      responses:
        '200':
          description: >-
            The rendered, JSON-decoded template and the context it was rendered
            against.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      result:
                        type: object
                        additionalProperties: {}
                        description: The rendered template output, parsed as a JSON object.
                      context:
                        type: object
                        additionalProperties: {}
                        description: >-
                          The resource context the template was rendered
                          against.
                    required:
                      - result
                      - context
                required:
                  - data
        '401':
          $ref: '#/components/responses/AuthenticationException'
        '403':
          $ref: '#/components/responses/AuthorizationException'
        '404':
          description: The requested resource could not be found.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      stage:
                        type: string
                        enum:
                          - resource
                        description: Always `resource` for this error.
                      message:
                        type: string
                        description: The captured failure message.
                      line:
                        type: integer
                        nullable: true
                        description: Always null for this error.
                    required:
                      - stage
                      - message
                      - line
                required:
                  - error
        '422':
          description: >-
            Either request validation failed, or the template failed to render
            or did not produce valid JSON.
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    title: Render or JSON error
                    description: >-
                      Returned when the Twig template fails to render, or its
                      output is not valid JSON.
                    properties:
                      error:
                        type: object
                        properties:
                          stage:
                            type: string
                            enum:
                              - render
                              - json
                            description: >-
                              Where the failure occurred: `render` for a Twig
                              error, `json` when the output could not be parsed
                              as JSON.
                          message:
                            type: string
                            description: The captured failure message.
                          line:
                            type: integer
                            nullable: true
                            description: >-
                              The template line that failed, when available.
                              Null for JSON errors.
                        required:
                          - stage
                          - message
                          - line
                      rendered_raw:
                        type: string
                        nullable: true
                        description: >-
                          The raw rendered template output. Populated when
                          `stage` is `json`, otherwise null.
                    required:
                      - error
                      - rendered_raw
                  - type: object
                    title: Validation error
                    description: >-
                      Returned when the request body fails validation, for
                      example when neither `template` nor `target_id` is
                      supplied.
                    properties:
                      message:
                        type: string
                        description: Errors overview.
                      errors:
                        type: object
                        description: >-
                          A detailed description of each field that failed
                          validation.
                        additionalProperties:
                          type: array
                          items:
                            type: string
                    required:
                      - message
                      - errors
components:
  schemas:
    PreviewTarget:
      type: object
      description: >-
        Provide either an inline `template` or a `target_id`. One of the two is
        required; if both are sent, the inline `template` takes precedence.
      properties:
        resource:
          type: string
          description: The resource type to render the template against.
          enum:
            - profile
            - transaction
            - transaction_item
            - order
            - order_item
            - reward
        resource_id:
          type: string
          description: The ID of the resource record to render against.
        template:
          type: string
          description: >-
            An inline Twig template to render. Required when `target_id` is
            omitted.
        target_id:
          type: integer
          description: >-
            The ID of an existing Target whose template to render. Required when
            `template` is omitted.
      required:
        - resource
        - resource_id
      anyOf:
        - required:
            - template
        - required:
            - target_id
      title: PreviewTarget
  responses:
    AuthenticationException:
      description: Unauthenticated
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    AuthorizationException:
      description: Authorization error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message

````