Update Template
Update an existing image template.
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
PUT https://api.ojo.so/v1/template/:templateIdPATCH on the same path does the same. Fields you leave out keep their value.
Path Parameters
| Parameter | Type | Description |
|---|---|---|
| templateId | string | The unique identifier of the template to update |
Headers
| Header | Value | Description |
|---|---|---|
| Content-Type | application/json | Specify that the request body is JSON |
Request Body
| Field | Type | Description |
|---|---|---|
| html | string | (Optional) 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 at least one field. A name or description alone changes it without rendering a new
preview.
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 update 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 PUT \
--url https://api.ojo.so/v1/template/<Replace with template ID> \
--header 'Authorization: Bearer <your API key>' \
--header 'Content-Type: application/json' \
--data '{
"html": "<h1>{{title}}</h1>",
"variables": {
"title": "Updated Template Title",
"content": "This is the updated content."
}
}'Response
200
Template successfully updated.
{
"id": "template-uuid-1",
"message": "Template updated"
}