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/template
Headers
Header | Value | Description |
---|---|---|
Content-Type | application/json | Specify that the request body is JSON |
Request Body
Field | Type | Description |
---|---|---|
html | string | The HTML content of the template (must be Base64 encoded) |
variables | object | (Optional) Variables used in the template |
The HTML content must be Base64 encoded. You can encode your HTML content using our HTML Encoder, or use standard Base64 encoding functions available in your programming language:
// JavaScript example
const encodedHtml = btoa('<div>Hello World!</div>');
# Python example
import base64
encoded_html = base64.b64encode('<div>Hello World!</div>'.encode()).decode()
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 --request POST \
--url https://api.ojo.so/v1/template \
--header 'Authorization: Bearer <API Key>' \
--header 'Content-Type: application/json' \
--header 'x-template-defaults: {"title":"Default Title"}' \
--data '{
"html": "...encoded HTML content...",
"variables": {
"title": "My Template Title"
}
}'
Response
Template successfully created.
{
"id": "template-uuid-123",
"message": "Template created successfully"
}