Set Template Variables
Replaces a template’s full set of variables: any variable you omit is removed. Media, character and voice variables bind to a node by element_id, listed under composition in GET /v3/templates/. A text variable with match turns that text into a {{name}} placeholder.
curl --request PUT \
--url https://api.heygen.com/v3/templates/{template_id}/variables \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"variables": {
"company": {
"match": "Acme",
"type": "text"
},
"first_name": {
"element_ids": [
"t81c0d4b"
],
"match": "John",
"type": "text"
},
"hero_image": {
"element_id": "i77e5f60",
"type": "image"
},
"narration_voice": {
"element_id": "t81c0d4b",
"type": "voice"
},
"presenter": {
"element_id": "a3f9c2e1",
"type": "character"
}
},
"expected_edit_version": "3"
}
'import requests
url = "https://api.heygen.com/v3/templates/{template_id}/variables"
payload = {
"variables": {
"company": {
"match": "Acme",
"type": "text"
},
"first_name": {
"element_ids": ["t81c0d4b"],
"match": "John",
"type": "text"
},
"hero_image": {
"element_id": "i77e5f60",
"type": "image"
},
"narration_voice": {
"element_id": "t81c0d4b",
"type": "voice"
},
"presenter": {
"element_id": "a3f9c2e1",
"type": "character"
}
},
"expected_edit_version": "3"
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
variables: {
company: {match: 'Acme', type: 'text'},
first_name: {element_ids: ['t81c0d4b'], match: 'John', type: 'text'},
hero_image: {element_id: 'i77e5f60', type: 'image'},
narration_voice: {element_id: 't81c0d4b', type: 'voice'},
presenter: {element_id: 'a3f9c2e1', type: 'character'}
},
expected_edit_version: '3'
})
};
fetch('https://api.heygen.com/v3/templates/{template_id}/variables', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.heygen.com/v3/templates/{template_id}/variables",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'variables' => [
'company' => [
'match' => 'Acme',
'type' => 'text'
],
'first_name' => [
'element_ids' => [
't81c0d4b'
],
'match' => 'John',
'type' => 'text'
],
'hero_image' => [
'element_id' => 'i77e5f60',
'type' => 'image'
],
'narration_voice' => [
'element_id' => 't81c0d4b',
'type' => 'voice'
],
'presenter' => [
'element_id' => 'a3f9c2e1',
'type' => 'character'
]
],
'expected_edit_version' => '3'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.heygen.com/v3/templates/{template_id}/variables"
payload := strings.NewReader("{\n \"variables\": {\n \"company\": {\n \"match\": \"Acme\",\n \"type\": \"text\"\n },\n \"first_name\": {\n \"element_ids\": [\n \"t81c0d4b\"\n ],\n \"match\": \"John\",\n \"type\": \"text\"\n },\n \"hero_image\": {\n \"element_id\": \"i77e5f60\",\n \"type\": \"image\"\n },\n \"narration_voice\": {\n \"element_id\": \"t81c0d4b\",\n \"type\": \"voice\"\n },\n \"presenter\": {\n \"element_id\": \"a3f9c2e1\",\n \"type\": \"character\"\n }\n },\n \"expected_edit_version\": \"3\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.heygen.com/v3/templates/{template_id}/variables")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"variables\": {\n \"company\": {\n \"match\": \"Acme\",\n \"type\": \"text\"\n },\n \"first_name\": {\n \"element_ids\": [\n \"t81c0d4b\"\n ],\n \"match\": \"John\",\n \"type\": \"text\"\n },\n \"hero_image\": {\n \"element_id\": \"i77e5f60\",\n \"type\": \"image\"\n },\n \"narration_voice\": {\n \"element_id\": \"t81c0d4b\",\n \"type\": \"voice\"\n },\n \"presenter\": {\n \"element_id\": \"a3f9c2e1\",\n \"type\": \"character\"\n }\n },\n \"expected_edit_version\": \"3\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.heygen.com/v3/templates/{template_id}/variables")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"variables\": {\n \"company\": {\n \"match\": \"Acme\",\n \"type\": \"text\"\n },\n \"first_name\": {\n \"element_ids\": [\n \"t81c0d4b\"\n ],\n \"match\": \"John\",\n \"type\": \"text\"\n },\n \"hero_image\": {\n \"element_id\": \"i77e5f60\",\n \"type\": \"image\"\n },\n \"narration_voice\": {\n \"element_id\": \"t81c0d4b\",\n \"type\": \"voice\"\n },\n \"presenter\": {\n \"element_id\": \"a3f9c2e1\",\n \"type\": \"character\"\n }\n },\n \"expected_edit_version\": \"3\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "77e650952c024c6188a35e23e7088617",
"name": "Quarterly Update",
"thumbnail_url": "<string>",
"aspect_ratio": "16:9",
"created_at": 1711929600,
"updated_at": 1711929600,
"variables": {},
"source_video_id": "<string>",
"edit_version": "3",
"scene_ids": [
"<string>"
],
"scenes": [
{
"scene_id": "<string>",
"script": "<string>",
"variables": [
{
"name": "<string>",
"variable_type": "<string>"
}
]
}
],
"composition": {
"scenes": [
{
"id": "<string>",
"background": {
"color": "<string>",
"type": "color"
},
"elements": [
{
"id": "<string>",
"avatar_id": "<string>",
"type": "avatar",
"engine": "avatar_vi",
"expressiveness": "high",
"motion_prompt": "<string>",
"bindable_as": [
"text"
],
"variable": "<string>",
"text_variables": [
"<string>"
]
}
],
"script": [
{
"id": "<string>",
"text": "<string>",
"type": "text",
"voice_id": "<string>",
"voice_settings": {
"speed": 123,
"pitch": 123,
"volume": 123,
"locale": "<string>",
"engine_settings": {
"engine_type": "elevenlabs",
"model": "eleven_multilingual_v2",
"similarity_boost": 0.5,
"stability": 0.5,
"style": 0.5,
"use_speaker_boost": true
}
},
"trim_to_speech": true,
"bindable_as": [
"text"
],
"variable": "<string>",
"text_variables": [
"<string>"
]
}
]
}
],
"background_audio": [
{
"id": "<string>",
"bindable_as": [
"text"
],
"variable": "<string>",
"text_variables": [
"<string>"
],
"type": "audio",
"url": "<string>"
}
]
}
}
}Authorizations
HeyGen API key. Obtain from your HeyGen dashboard.
Path Parameters
Unique template identifier
Body
Request body for PUT /v3/templates/{template_id}/variables.
Full replacement: the body is the complete variable set after the call. A variable that exists on the template but is missing here is removed.
The complete variable set, keyed by variable name (letters, digits, underscores; must start with a letter or underscore; at most 64 characters). An empty object removes every variable.
Show child attributes
Show child attributes
{
"company": { "match": "Acme", "type": "text" },
"first_name": {
"element_ids": ["t81c0d4b"],
"match": "John",
"type": "text"
},
"hero_image": { "element_id": "i77e5f60", "type": "image" },
"narration_voice": { "element_id": "t81c0d4b", "type": "voice" },
"presenter": {
"element_id": "a3f9c2e1",
"type": "character"
}
}
The template's edit_version from your last GET. When given, the update is rejected with 409 stale_edit_version if the template changed since. Omit to overwrite unconditionally.
1"3"
Response
Successful response
Template detail: its variable schema, the July scene summary and, for authoring workspaces, its composition.
Show child attributes
Show child attributes
curl --request PUT \
--url https://api.heygen.com/v3/templates/{template_id}/variables \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"variables": {
"company": {
"match": "Acme",
"type": "text"
},
"first_name": {
"element_ids": [
"t81c0d4b"
],
"match": "John",
"type": "text"
},
"hero_image": {
"element_id": "i77e5f60",
"type": "image"
},
"narration_voice": {
"element_id": "t81c0d4b",
"type": "voice"
},
"presenter": {
"element_id": "a3f9c2e1",
"type": "character"
}
},
"expected_edit_version": "3"
}
'import requests
url = "https://api.heygen.com/v3/templates/{template_id}/variables"
payload = {
"variables": {
"company": {
"match": "Acme",
"type": "text"
},
"first_name": {
"element_ids": ["t81c0d4b"],
"match": "John",
"type": "text"
},
"hero_image": {
"element_id": "i77e5f60",
"type": "image"
},
"narration_voice": {
"element_id": "t81c0d4b",
"type": "voice"
},
"presenter": {
"element_id": "a3f9c2e1",
"type": "character"
}
},
"expected_edit_version": "3"
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
variables: {
company: {match: 'Acme', type: 'text'},
first_name: {element_ids: ['t81c0d4b'], match: 'John', type: 'text'},
hero_image: {element_id: 'i77e5f60', type: 'image'},
narration_voice: {element_id: 't81c0d4b', type: 'voice'},
presenter: {element_id: 'a3f9c2e1', type: 'character'}
},
expected_edit_version: '3'
})
};
fetch('https://api.heygen.com/v3/templates/{template_id}/variables', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.heygen.com/v3/templates/{template_id}/variables",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'variables' => [
'company' => [
'match' => 'Acme',
'type' => 'text'
],
'first_name' => [
'element_ids' => [
't81c0d4b'
],
'match' => 'John',
'type' => 'text'
],
'hero_image' => [
'element_id' => 'i77e5f60',
'type' => 'image'
],
'narration_voice' => [
'element_id' => 't81c0d4b',
'type' => 'voice'
],
'presenter' => [
'element_id' => 'a3f9c2e1',
'type' => 'character'
]
],
'expected_edit_version' => '3'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.heygen.com/v3/templates/{template_id}/variables"
payload := strings.NewReader("{\n \"variables\": {\n \"company\": {\n \"match\": \"Acme\",\n \"type\": \"text\"\n },\n \"first_name\": {\n \"element_ids\": [\n \"t81c0d4b\"\n ],\n \"match\": \"John\",\n \"type\": \"text\"\n },\n \"hero_image\": {\n \"element_id\": \"i77e5f60\",\n \"type\": \"image\"\n },\n \"narration_voice\": {\n \"element_id\": \"t81c0d4b\",\n \"type\": \"voice\"\n },\n \"presenter\": {\n \"element_id\": \"a3f9c2e1\",\n \"type\": \"character\"\n }\n },\n \"expected_edit_version\": \"3\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.heygen.com/v3/templates/{template_id}/variables")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"variables\": {\n \"company\": {\n \"match\": \"Acme\",\n \"type\": \"text\"\n },\n \"first_name\": {\n \"element_ids\": [\n \"t81c0d4b\"\n ],\n \"match\": \"John\",\n \"type\": \"text\"\n },\n \"hero_image\": {\n \"element_id\": \"i77e5f60\",\n \"type\": \"image\"\n },\n \"narration_voice\": {\n \"element_id\": \"t81c0d4b\",\n \"type\": \"voice\"\n },\n \"presenter\": {\n \"element_id\": \"a3f9c2e1\",\n \"type\": \"character\"\n }\n },\n \"expected_edit_version\": \"3\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.heygen.com/v3/templates/{template_id}/variables")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"variables\": {\n \"company\": {\n \"match\": \"Acme\",\n \"type\": \"text\"\n },\n \"first_name\": {\n \"element_ids\": [\n \"t81c0d4b\"\n ],\n \"match\": \"John\",\n \"type\": \"text\"\n },\n \"hero_image\": {\n \"element_id\": \"i77e5f60\",\n \"type\": \"image\"\n },\n \"narration_voice\": {\n \"element_id\": \"t81c0d4b\",\n \"type\": \"voice\"\n },\n \"presenter\": {\n \"element_id\": \"a3f9c2e1\",\n \"type\": \"character\"\n }\n },\n \"expected_edit_version\": \"3\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "77e650952c024c6188a35e23e7088617",
"name": "Quarterly Update",
"thumbnail_url": "<string>",
"aspect_ratio": "16:9",
"created_at": 1711929600,
"updated_at": 1711929600,
"variables": {},
"source_video_id": "<string>",
"edit_version": "3",
"scene_ids": [
"<string>"
],
"scenes": [
{
"scene_id": "<string>",
"script": "<string>",
"variables": [
{
"name": "<string>",
"variable_type": "<string>"
}
]
}
],
"composition": {
"scenes": [
{
"id": "<string>",
"background": {
"color": "<string>",
"type": "color"
},
"elements": [
{
"id": "<string>",
"avatar_id": "<string>",
"type": "avatar",
"engine": "avatar_vi",
"expressiveness": "high",
"motion_prompt": "<string>",
"bindable_as": [
"text"
],
"variable": "<string>",
"text_variables": [
"<string>"
]
}
],
"script": [
{
"id": "<string>",
"text": "<string>",
"type": "text",
"voice_id": "<string>",
"voice_settings": {
"speed": 123,
"pitch": 123,
"volume": 123,
"locale": "<string>",
"engine_settings": {
"engine_type": "elevenlabs",
"model": "eleven_multilingual_v2",
"similarity_boost": 0.5,
"stability": 0.5,
"style": 0.5,
"use_speaker_boost": true
}
},
"trim_to_speech": true,
"bindable_as": [
"text"
],
"variable": "<string>",
"text_variables": [
"<string>"
]
}
]
}
],
"background_audio": [
{
"id": "<string>",
"bindable_as": [
"text"
],
"variable": "<string>",
"text_variables": [
"<string>"
],
"type": "audio",
"url": "<string>"
}
]
}
}
}
