Replace Text In Template

In this guide, you'll learn how to replace texts 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": "text_0",
            "properties": [
              {
                "default": "New Title",
                "name": "text"
              }
            ],
            "type": "text"
          }
        ]
      }
    ],
    "template_id": "0b21bdf5bb884e679add9e3bb3e8d6e9",
    "video_id": "0b21bdf5bb884e679add9e3bb3e8d6e9"
  },
  "message": "Success"
}

Customize Template Variables and Generate Video

Now, you can proceed to replace the text 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": "0b21bdf5bb884e679add9e3bb3e8d6e9",
  "title": "video_title",
  "variables": [
    {
      "properties": {
        "text": "welcome to HeyGen"
      },
      "name": "text_0"
    }
  ],
  "test": false
}'

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 text within the template:

As you can see, with HeyGen's API, you can seamlessly replace text content within templates, offering endless possibilities for customization and personalization.