template
ObjectTemplates are reusable HTML, CSS, and JavaScript snippets that can be used to generate PDFs or images. The template
object represents a template in the MarkupGo API.
Heads up! 💡
html
, css
, context
, libraries
, format
, autoHeight
, width
, and height
fields can be overridden when generating a PDF or image from a template. If any field is not provided, the default value will be used.
Please see the pdf and image endpoints for more information.
Key | Description |
---|---|
id | The unique identifier of the template. |
name | The name of the template. |
format | The default export format of the template. |
html | The HTML content of the template. |
css | The CSS content of the template. |
width | The width of the template in pixels. |
height | The height of the template in pixels. |
context | The template context. |
autoHeight | Whether to automatically adjust the height of the template. |
libraries | The template libraries. |
libraries.js | The template JavaScript libraries. |
libraries.css | The template CSS libraries. |
createdAt | The date and time the template was created. |
updatedAt | The date and time the template was last updated. |
type Template = {
id: string
owner: User
name: string
html: string
css: string
width: number
height: number
lastTask: Task
context: string
autoHeight: boolean
libraries: {
js: string[]
css: string[]
}
format: 'pdf' | 'png' | 'jpeg' | 'webp'
usage?: number
isDeleted?: boolean
deletedAt?: string
}
{
"id": "666b3561fbaa04f6877e70b5",
"name": "My Template",
"context": {
"name": "John Doe"
},
"html": "<h1>Hello, {{name}}!</h1>",
"css": "h1 { color: red; }",
"libraries": {
"js": ["https://cdn.tailwindcss.com"],
"css": ["https://example.com/style.css"]
},
"autoHeight": false,
"createdAt": "2026-06-21T10:00:00Z",
"updatedAt": "2026-06-21T10:05:00Z"
}
The /templates
endpoint returns a list of templates.
The response contains an array of templates and a meta object with pagination information. Please see the template object for more information.
GET /templates
fetch('/api/v1/templates', {
method: 'GET',
headers: {
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
})
The /templates/:id
endpoint returns a template by its ID.
The response contains a template object. Please see the template object for more information.
GET /templates/:id
fetch('/api/v1/templates/666b3561fbaa04f6877e70b5', {
method: 'GET',
headers: {
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
})
The /templates
endpoint creates a new template.
The request body must contain a JSON object with the template fields.
Key | Description |
---|---|
name | The name of the template. |
context | The template context. |
html | The template HTML content. |
css | The template CSS content. |
libraries | The template libraries. |
libraries.js | The template JavaScript libraries. |
libraries.css | The template CSS libraries. |
autoHeight | Whether to automatically adjust the height of the template. |
The response contains a template object. Please see the template object for more information.
POST /templates
fetch('/api/v1/templates', {
method: 'POST',
headers: {
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'My Template',
context: {
name: 'John Doe'
},
html: '<h1>Hello, {{name}}!</h1>',
css: 'h1 { color: red; }',
libraries: {
js: ['https://cdn.tailwindcss.com'],
css: ['https://example.com/style.css']
},
autoHeight: false
})
})
The /templates/:id
endpoint updates a template by its ID.
The request body must contain a JSON object with the template fields.
Key | Description |
---|---|
name | The name of the template. |
context | The template context. |
html | The template HTML content. |
css | The template CSS content. |
libraries | The template libraries. |
libraries.js | The template JavaScript libraries. |
libraries.css | The template CSS libraries. |
autoHeight | Whether to automatically adjust the height of the template. |
The response contains a template object. Please see the template object for more information.
PUT /templates/:id
fetch('/api/v1/templates/666b3561fbaa04f6877e70b5', {
method: 'PUT',
headers: {
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'My Template Updated',
context: {
name: 'Jr. Doe'
},
html: '<h1>Hello, {{name}}! Updated</h1>',
css: 'h1 { color: red; }',
libraries: {
js: ['https://cdn.tailwindcss.com'],
css: ['https://example.com/style.css']
},
autoHeight: false
})
})
The /templates/:id
endpoint deletes a template by its ID.
The response contains a message indicating the template was deleted successfully.
DELETE /templates/:id
fetch('/api/v1/templates/666b3561fbaa04f6877e70b5', {
method: 'DELETE',
headers: {
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
})
{
"success": true,
}