---
title: "replaceTemplatesV2"
method: POST
path: "/v2/template:replace"
tags: ["Templates"]
---

# replaceTemplatesV2

`POST /v2/template:replace`

Replace variables in handlebars templates with raw value preservation

V2 returns parsed outputs that preserve the original data types (arrays, objects, strings)
instead of stringifying always. Variables with strings mixed with other variables will be returned in the stringified format. 
Alongside the parsed outputs for every single variable.

Takes in an array of input templates and outputs an object mapping each input and variable
to their rendered values with type preservation.

## Request body

- object
  - `inputs` string[]
  - `parameters` VariableParameters
    - `template_type` 'email' | 'document', required
    - `language` string — 2-letter language code (ISO 639-1)
    - `main_entity_id` string, uuid — The main entity ID. Use main entity in order to use the variable without schema slug prefix - or just pass directly to other object ID.
    - `brand_id` number, nullable — Brand ID
    - `user_id` string, nullable — User ID
    - `user_org_id` string, nullable — Organization ID of the user
    - `custom_variables` ExternalCustomVariable[] — Custom variables with specified values form other services.
      - `variable` string
      - `value` string
    - `context_data` object — If context data is available, this data will be used for variable replace.
    - `template_name` string — The name of email template
    - `template_tags` string[] — The tags of email template
    - `template_id` string — The Id of email template
    - `variables_version` string — The version of the variables syntax supported. Default is 1.0

## Response `200`

ok

- ReplacementOutputV2
  - `outputs` object — Dictionary mapping input templates and variable names to their resolved output values. Values preserve their original types (string, array, object) instead of being stringified. Keys include: - Original input templates (e.g., "Hello {{name}}") - Individual variables found in templates (e.g., "{{name}}", "{{product_images[*].public_url}}")

---

[API](https://skmtc.dev/epilot/apis/template-variables-api.md) · [All operations](https://skmtc.dev/epilot/apis/template-variables-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/epilot/template-variables-api/revisions/ff0c1e3dc198/schema)
