# Replace Video in Template

Easily replace video elements within HeyGen template using API

In this guide, we will learn how to replace **videos** within a template and generate a video.

### Video Properties:

* **url:** URL of the video content.
* **asset\_id:** Asset ID of the video content.
* **play\_style:** Video playback style. Available options are: `fit_to_scene`, `freeze`, `loop`, `full_video`. See how each playback mode affects video rendering in [Video Playback Styles in Template](https://docs.heygen.com/docs/video-playback-styles-in-template-1).

<Callout icon="📘" theme="info">
  *url* and *asset\_id* can be retrieved from the [Upload Asset](https://movio-api.readme.io/reference/upload-asset) endpoint.
</Callout>

# Creating Template through the Interface

To create a new template:

1. Go to the HeyGen Dashboard and open the [Templates](https://app.heygen.com/templates) tab.
2. Click **Create Template**. This opens the template editor.
3. Click the **Media** tab and select an existing video or upload a new one.
4. Use the **API** icon in the toolbar to assign an **API variable** to the video.

<Image border={false} src="https://files.readme.io/df7f9d7a18e3a6513c727140ab7942cded7f8661c92bcf61cb51c44e2584fc8f-video_api_variable-modified.png" />

As you can see, we have assigned a variable name, i.e., `shopping_video` to our video element. In this tutorial, we will demonstrate how to change this video using the Template API.

# Get a List of Your Templates

For instructions on listing your templates that you have created in the HeyGen interface and retrieving the `template_id`, see [Get a List of Templates](https://movio-api.readme.io/docs/generate-video-from-template-v3#get-a-list-of-your-templates).

# Retrieve Template Elements

To retrieve template elements you will need to submit an API request as follows. In the response, you’ll receive details of all variables defined in the template, in this case, the video element details, which can later be modified when creating videos.

```bash Request
curl --request GET \
     --url https://api.heygen.com/v3/template/<template_id> \
     --header 'accept: application/json' \
     --header 'x-api-key: <your-api-key>'

```

```json Response
{
  "error": null,
  "data": {
    "version": "4",
    "variables": {
      "shopping_video": {
        "name": "shopping_video",
        "type": "video",
        "properties": {
          "url": "<url>",
          "asset_id": null,
          "play_style": "loop",
          "fit": "none"
        }
      }
    },
    "scenes": [
      {
        "id": "<scene_id>",
        "script": "",
        "variables": {
           "shopping_video": {
             "name": "shopping_video",
             "type": "video"
        }
      }
    ]
  }
}

```

For a full list of parameters and complete response details, see detailed API Reference: [Retrieve Template Details (V3)](https://movio-api.readme.io/reference/get-template-v3).

# Modify Template Elements and Generate Video

To change template elements and generate videos, you will need to submit an API request as follows. In the request body, *specify the elements you want to modify* by providing the appropriate object within the *variables* section.

```bash Request
curl --location 'https://api.heygen.com/v2/template/<template_id>/generate' \
     --header 'X-Api-Key: <your-api-key>' \
     --header 'Content-Type: application/json' \
     --data '{
  "caption": false,
  "title": "New Video",
  "variables": {
    "shopping_video": {
      "name": "shopping_video",
      "type": "video",
      "properties": {
        "url": "https://files.heygencdn.com/prod/movio/preset/video/origin/0aec3387a37c43f1abd463378d261f3c.mp4",
        "asset_id": null,
        "play_style": "loop"
      }
    }
  }
}'
```

```json Response
{
  "error": null,
  "data": {
    "video_id": "<video_id>"
  }
}
```

If you want to explore all configurable options - including how to update multiple elements or adjust video metadata, see detailed API Reference: [Generate Video from Template](https://movio-api.readme.io/reference/generate-from-template-v3)

You will receive a `video_id` after your request. To check the video's status and retrieve further details, you can use the [Retrieve Video Status/Details](https://movio-api.readme.io/reference/video-status)  API endpoint. You can view complete status response examples on the right-side **Response** panel of the API Reference page - open the **Examples** dropdown to view responses for different video statuses. You can select any example to preview the corresponding response body.

### Status Descriptions

**`pending`**\
The video is queued and waiting to start rendering.

**`waiting`**\
The video is in waiting state.

**`processing`**\
The video is currently rendering.

**`completed`**\
The video has successfully rendered and is ready for download.

**`failed`**\
The video could not be rendered due to an error (for example, if the duration exceeds plan limits).

And using the Template API, we changed the video element and generated our new video.

**Before:**

<Image border={false} src="https://files.readme.io/bb232f1fdf040a5b55bdbd8c3106a6c31e6a8ab76cf87853df3f6f9f96b0fb3e-image.png" />

**After:**

<Image border={false} src="https://files.readme.io/1b58e2deef2a1954c754cd2ccddc920e2855219cfb76633ca98382b2ee9be0a5-image.png" />

# Conclusion

In this guide, we've walked you through the process of *replacing videos* within a template video using **HeyGen's Template API**. By following the steps outlined here, you can modify video elements to create customized videos that suit your specific needs.