Skip to Content
Update Template

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/:templateId

PATCH on the same path does the same. Fields you leave out keep their value.

Path Parameters

ParameterTypeDescription
templateIdstringThe unique identifier of the template to update

Headers

HeaderValueDescription
Content-Typeapplication/jsonSpecify that the request body is JSON

Request Body

FieldTypeDescription
htmlstring(Optional) The HTML of the template, as a plain string
variablesobject(Optional) Variables used in the template
namestring(Optional) The template’s name, 1 to 120 characters
descriptionstring(Optional) A description of the template, at most 300 characters
viewportWidthnumber(Optional) The template’s default width in pixels
viewportHeightnumber(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 --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

Template successfully updated.

{ "id": "template-uuid-1", "message": "Template updated" }