Create Image from Template
Send a POST request to this endpoint to create a new image using a predefined template.
You will need to authenticate to use this API. See authentication.
This endpoint consumes 1 credit per image. The credit is spent when the render starts, and a render that fails costs nothing: its credit is refunded.
Request
POST https://api.ojo.so/v1/image/templateRequest Body
| Parameter | Type | Description |
|---|---|---|
| templateId | string | The ID of the template to use |
| modify | object | (Optional) An object containing variables to modify in the template |
| viewportHeight | number | (Optional) Height of the viewport in pixels (default: 800) |
| viewportWidth | number | (Optional) Width of the viewport in pixels (default: 1280) |
| transparentBackground | boolean | (Optional) When set to true, generates the image with a transparent background. Defaults to false if not specified. |
| strict | boolean | (Optional) When true, answers 422 instead of rendering when there would be warnings. See Variables and warnings |
cURL
curl --request POST \
--url https://api.ojo.so/v1/image/template \
--header 'Authorization: Bearer <your API key>' \
--header 'Content-Type: application/json' \
--data '{
"templateId": "your-template-id",
"modify": {
"title": "Custom Title"
},
"viewportHeight": 1000,
"viewportWidth": 1500
}'Variables and warnings
modify merges over the template’s saved variables. Objects merge key by key, so
{"issuer": {"signatory": "X"}} keeps the saved issuer.name. An array replaces the saved array
whole. A key you leave out prints its saved value, which is usually sample data.
When modify is not empty, the response lists warnings for:
- a key the template does not read:
'recipent_name' is not used by the template - an input you left out that printed its saved value:
'recipient_name' was not sent, so the stored sample value was used - an input you left out that has no saved value:
'x' was not sent and has no stored value, so it renders empty - a request field the API does not know, such as a misspelt option:
Unknown field `vieportWidth` was ignored. These are listed even whenmodifyis empty
At most 20 are listed, then and N more. Send "strict": true to get these as a 422 instead,
before anything is rendered or charged. The paths a template reads are listed as inputs by
Get Template.
Response
200
Everything went as planned and your image is generated.
{
"id": "image-id",
"imageUrl": "https://example.com/path/to/image.png",
"createdAt": "2023-08-29T12:34:56Z"
}