Replace Avatar In Template
In this guide, you'll learn how to replace avatar within a template video. You can view the example template video here.
Retrieve Template Variables
You can fetch the template variables using the following API call:
curl -X GET 'https://api.heygen.com/v1/template.get?video_id=<video_id>' \
-H 'X-Api-Key: <your-api-key>'
{
"code": 100,
"data": {
"scenes": [
{
"variables": [
{
"name": "avatar_0",
"properties": [
{
"default": "Monica_inSleeveless _20220819",
"name": "id"
},
{
"default": "Discover affordable furniture and home furnishing inspiration for all sizes of wallets and homes. Shop online or find a store near you.",
"name": "text"
},
{
"default": "1bd001e7e50f421d891986aad5158bc8",
"name": "voice_id"
}
],
"type": "avatar"
}
]
}
],
"template_id": "412931bd533c47f3a1990849bca11693",
"video_id": "412931bd533c47f3a1990849bca11693"
},
"message": "Success"
}
Customize Template Variables and Generate Video
Now, you can proceed to replace the avatar's id
variable in your template. Use the following API request:
curl --request POST \
--url https://api.heygen.com/v1/template.generate \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <your-api-key>' \
--data '
{
"template_id": "a0bdcdb475ab46038b697d28b0397c96",
"title": "Replace Avatar",
"variables": [
{
"properties": {
"id": "Zoey-insuit-20220816"
},
"name": "avatar_0"
}
],
"test": true
}'
{
"code": 100,
"data": {
"video_id": "<video_id>"
},
"message": "Success"
}
View the Result
Let's take a look at how a template video can be transformed. Below, you'll find the original template video and the video after customizing it.
Here's the original template video:
And here's the video after customizing it, where we've replaced the avatar within the template:
As you can see, with HeyGen's API, you can seamlessly replace avatar content within templates, offering endless possibilities for customization and personalization.
Updated 22 days ago