Api

Templates

Templates are reusable HTML, CSS, and JavaScript snippets that can be used to generate PDFs or images.

Templates

The template Object

Templates 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.

Properties

KeyDescription
idThe unique identifier of the template.
nameThe name of the template.
formatThe default export format of the template.
htmlThe HTML content of the template.
cssThe CSS content of the template.
widthThe width of the template in pixels.
heightThe height of the template in pixels.
contextThe template context.
autoHeightWhether to automatically adjust the height of the template.
librariesThe template libraries.
libraries.jsThe template JavaScript libraries.
libraries.cssThe template CSS libraries.
createdAtThe date and time the template was created.
updatedAtThe date and time the template was last updated.
Type Definition
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
}
Template
{
  "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"
}

GET /templates

The /templates endpoint returns a list of templates.

Response

The response contains an array of templates and a meta object with pagination information. Please see the template object for more information.

GET /templates
Request
fetch('/api/v1/templates', {
  method: 'GET',
  headers: {
    'x-api-key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
})

GET /templates/:id

The /templates/:id endpoint returns a template by its ID.

Response

The response contains a template object. Please see the template object for more information.

GET /templates/:id
Request
fetch('/api/v1/templates/666b3561fbaa04f6877e70b5', {
  method: 'GET',
  headers: {
    'x-api-key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
})

POST /templates

The /templates endpoint creates a new template.

Request Body

The request body must contain a JSON object with the template fields.

KeyDescription
nameThe name of the template.
contextThe template context.
htmlThe template HTML content.
cssThe template CSS content.
librariesThe template libraries.
libraries.jsThe template JavaScript libraries.
libraries.cssThe template CSS libraries.
autoHeightWhether to automatically adjust the height of the template.

Response

The response contains a template object. Please see the template object for more information.

POST /templates
Request
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
  })
})

PUT /templates/:id

The /templates/:id endpoint updates a template by its ID.

Request Body

The request body must contain a JSON object with the template fields.

KeyDescription
nameThe name of the template.
contextThe template context.
htmlThe template HTML content.
cssThe template CSS content.
librariesThe template libraries.
libraries.jsThe template JavaScript libraries.
libraries.cssThe template CSS libraries.
autoHeightWhether to automatically adjust the height of the template.

Response

The response contains a template object. Please see the template object for more information.

PUT /templates/:id
Request
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
  })
})

DELETE /templates/:id

The /templates/:id endpoint deletes a template by its ID.

Response

The response contains a message indicating the template was deleted successfully.

DELETE /templates/:id
Request
fetch('/api/v1/templates/666b3561fbaa04f6877e70b5', {
  method: 'DELETE',
  headers: {
    'x-api-key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
})
Response
{
  "success": true,
}