Archived docs Get your API Key
Get started
Tutorials
Guides
Reference
Help for coding agents
๐Ÿค– AI Assistant

11. Templates

Variables let one JSON serve many properties. Templates let your application avoid sending that JSON at all โ€” store the movie once in your Dashboard, then trigger a render with { "template": "<id>", "variables": { ... } }. This chapter walks through saving the chapter-10 movie as a template and calling it from the API.

Prerequisites: chapter 10. The template body is the chapter-10 movie with placeholders.

Step 1 โ€” Save the movie as a template

Two ways:

  1. Dashboard. Paste the chapter-10 movie JSON into the visual editor โ†’ click Save as template โ†’ give it a name (e.g. real-estate-listing-v1).
  2. API. Submit POST /v2/templates with the body:
{
  "name": "real-estate-listing-v1",
  "movie": { ... the full chapter-10 JSON, minus the variables block ... }
}

The response contains a templateId โ€” a random 20-character alphanumeric string generated by the API, for example LerKrmBfiqaIgBuacLWn. Keep this ID โ€” it's what you'll use to render the template. The name you provided is only a human-friendly label shown in the dashboard list; every API reference to the template (rendering, fetching, updating, deleting) uses the random ID, not the name.

Step 2 โ€” Call the template

Once saved, the rendering payload shrinks. Submit POST /v2/movies with the template ID plus the variables for the specific property (replace LerKrmBfiqaIgBuacLWn with the ID returned for your own template):

{
  "template": "LerKrmBfiqaIgBuacLWn",
  "variables": {
    "address": "47 Cedar Avenue, Seattle, WA",
    "price": "$1,200,000",
    "bedrooms": "5",
    "agent_name": "Pat Morgan"
  }
}

The server loads the template, merges the request's variables on top, and renders the result. Same output as chapter 10 โ€” just less payload.

Step 3 โ€” Override the resolution / quality at call time

A few movie-level fields are taken from the request, not the template: resolution, width, height, quality, exports, and client-data. This lets one template power vertical-9:16 and horizontal-16:9 outputs without duplicating the JSON.

{
  "template": "LerKrmBfiqaIgBuacLWn",
  "resolution": "instagram-story",
  "quality": "medium",
  "variables": {
    "address": "47 Cedar Avenue, Seattle, WA",
    "price": "$1,200,000",
    "bedrooms": "5"
  }
}

Step 4 โ€” Submit from your favourite SDK

The call looks identical to chapter 7, only the body differs:

curl -X POST https://api.json2video.com/v2/movies \
  -H "x-api-key: $JSON2VIDEO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "LerKrmBfiqaIgBuacLWn",
    "variables": {
      "address": "47 Cedar Avenue, Seattle, WA",
      "price": "$1,200,000",
      "bedrooms": "5"
    }
  }'
await fetch("https://api.json2video.com/v2/movies", {
  method: "POST",
  headers: {
    "x-api-key": process.env.JSON2VIDEO_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    template: "LerKrmBfiqaIgBuacLWn",
    variables: {
      address: "47 Cedar Avenue, Seattle, WA",
      price: "$1,200,000",
      bedrooms: "5",
    },
  }),
});
import os, requests
requests.post(
    "https://api.json2video.com/v2/movies",
    headers={"x-api-key": os.environ["JSON2VIDEO_API_KEY"]},
    json={
        "template": "LerKrmBfiqaIgBuacLWn",
        "variables": {
            "address": "47 Cedar Avenue, Seattle, WA",
            "price": "$1,200,000",
            "bedrooms": "5",
        },
    },
)
<?php
$body = json_encode([
    "template" => "LerKrmBfiqaIgBuacLWn",
    "variables" => [
        "address" => "47 Cedar Avenue, Seattle, WA",
        "price" => "$1,200,000",
        "bedrooms" => "5",
    ],
]);
$ch = curl_init("https://api.json2video.com/v2/movies");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ["x-api-key: " . getenv("JSON2VIDEO_API_KEY"), "Content-Type: application/json"],
    CURLOPT_POSTFIELDS => $body,
]);
echo curl_exec($ch);

The complete final JSON

A render request that uses the template โ€” replace the body of POST /v2/movies with this (substituting your own template ID):

{
  "template": "LerKrmBfiqaIgBuacLWn",
  "resolution": "full-hd",
  "variables": {
    "address": "123 Oak Street",
    "price": "$849,000",
    "bedrooms": "4",
    "agent_name": "Jordan Lee"
  }
}

Expected output

Same 16-second video as chapter 10. The win is on the client side: your CRM only needs to remember the template ID plus the per-property variables. Sample render: tutorial-11.mp4 (placeholder).

What you learned

  • A template is the movie JSON stored on the server, identified by a random 20-character ID generated by the API (e.g. LerKrmBfiqaIgBuacLWn). The name you set is only a label for the dashboard list โ€” every API call references the template by its ID.
  • POST /v2/movies accepts either a full movie body or a template + variables body.
  • Request-level fields (resolution, quality, exports, client-data) override the stored template.
  • Templates are managed via the Dashboard or the /v2/templates endpoint family.

Going further

For a deeper dive on the dashboard side, see Guides โ†’ Dashboard โ†’ Templates.

Previous chapter / Next chapter

โ† 10. Variables ยท 12. Expressions โ†’