Create Template
Create a new image template that can be used for generating images.
You will need to authenticate to use this API. See authentication.
The template system supports various Handlebars helpers for dynamic content manipulation. Check out the Template Helpers section to learn about available helpers for formatting dates, performing calculations, manipulating strings, and more.
Request
POST https://api.ojo.so/v1/templateHeaders
| Header | Value | Description |
|---|---|---|
| Content-Type | application/json | Specify that the request body is JSON |
Request Body
| Field | Type | Description |
|---|---|---|
| html | string | The HTML of the template, as a plain string |
| variables | object | (Optional) Variables used in the template |
| name | string | (Optional) The template’s name, 1 to 120 characters |
| description | string | (Optional) A description of the template, at most 300 characters |
| viewportWidth | number | (Optional) The template’s default width in pixels |
| viewportHeight | number | (Optional) The template’s default height in pixels |
Send the HTML as a plain JSON string. Your JSON library escapes quotes, newlines and other characters for you:
// JavaScript example
const body = JSON.stringify({ html: '<h1>{{title}}</h1>', variables: { title: 'Hello' } });# Python example
import json
body = json.dumps({'html': '<h1>{{title}}</h1>', 'variables': {'title': 'Hello'}})Dynamic Template
You can create your template with Handlebars expressions and generate images by providing the necessary data. When making a request to generate an image, include a modify object in your request body with the data to populate your Handlebars placeholders. Learn how to create image with variables.
Example:
{
"templateId": "template-uuid-123",
"modify": {
"title": "Welcome to Our Site",
"user": {
"name": "Alice Smith"
},
"showDetails": true,
"items": ["Item 1", "Item 2", "Item 3"]
}
}cURL
curl --request POST \
--url https://api.ojo.so/v1/template \
--header 'Authorization: Bearer <your API key>' \
--header 'Content-Type: application/json' \
--data '{
"html": "<h1>{{title}}</h1>",
"variables": {
"title": "My Template Title"
}
}'Response
201
Template successfully created. The Location header holds its address, /v1/template/<id>.
Before 2026-10-27 this answered 200, so treat 200 and 201 alike.
{
"id": "template-uuid-123",
"message": "Template created"
}