Skip to main content

Get templates

curl -u 'username:password' 'https://listmonk.mysite.com/api/templates'
Retrieves all email templates. Authentication: Required
Permission: templates:get

Query Parameters

no_body
boolean
default:"false"
If true, excludes template body from response for faster loading

Response

data
array
Array of template objects

Get template

curl -u 'username:password' 'https://listmonk.mysite.com/api/templates/1'
Retrieves a single template by ID. Authentication: Required
Permission: templates:get

Path Parameters

id
integer
required
Template ID

Query Parameters

no_body
boolean
default:"false"
If true, excludes template body

Response

data
object
Returns a single template object

Create template

curl -u 'username:password' 'https://listmonk.mysite.com/api/templates' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Newsletter Template",
    "type": "campaign",
    "body": "<!DOCTYPE html><html><body>{{ template \"content\" . }}</body></html>"
  }'
Creates a new email template. Authentication: Required
Permission: templates:manage

Request Body

name
string
required
Template name (max 2000 characters)
type
string
required
Template type:
  • campaign: For email campaigns (must contain {{ template "content" . }} placeholder)
  • tx: For transactional emails
body
string
required
Template HTML body. Campaign templates must include the {{ template "content" . }} placeholder where campaign content will be inserted.
subject
string
Email subject line (required for tx templates, ignored for campaign templates)
body_source
string
Original template source for visual editor templates

Response

data
object
Returns the created template object

Example: Campaign Template

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <style>
    body { font-family: Arial, sans-serif; }
    .container { max-width: 600px; margin: 0 auto; }
  </style>
</head>
<body>
  <div class="container">
    <h1>{{ .Campaign.Name }}</h1>
    {{ template "content" . }}
    <footer>
      <a href="{{ UnsubscribeURL }}">Unsubscribe</a>
    </footer>
  </div>
</body>
</html>

Example: Transactional Template

<!DOCTYPE html>
<html>
<body>
  <h1>Welcome {{ .Subscriber.Name }}!</h1>
  <p>Your account has been created.</p>
  {{ if .Tx.Data.username }}
    <p>Username: {{ .Tx.Data.username }}</p>
  {{ end }}
</body>
</html>

Update template

curl -u 'username:password' -X PUT 'https://listmonk.mysite.com/api/templates/1' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Updated Template Name",
    "body": "<!DOCTYPE html><html><body>{{ template \"content\" . }}</body></html>"
  }'
Updates an existing template. Authentication: Required
Permission: templates:manage

Path Parameters

id
integer
required
Template ID

Request Body

name
string
Template name
body
string
Template HTML body
subject
string
Email subject (for tx templates)
body_source
string
Template source
The template type cannot be changed after creation. Only provided fields will be updated.

Set default template

curl -u 'username:password' -X PUT 'https://listmonk.mysite.com/api/templates/1/default'
Sets a template as the default template for new campaigns. Authentication: Required
Permission: templates:manage

Path Parameters

id
integer
required
Template ID to set as default

Response

data
array
Returns the updated list of all templates

Delete template

curl -u 'username:password' -X DELETE 'https://listmonk.mysite.com/api/templates/1'
Deletes a template. The default template cannot be deleted. Authentication: Required
Permission: templates:manage

Path Parameters

id
integer
required
Template ID

Response

data
boolean
Returns true on successful deletion
Campaigns using this template will not be affected as the template body is compiled into the campaign when it’s created.

Preview template

curl -u 'username:password' 'https://listmonk.mysite.com/api/templates/1/preview'
Generates an HTML preview of a template with dummy data. Authentication: Required
Permission: templates:get

Path Parameters

id
integer
required
Template ID

Response

Returns rendered HTML preview with sample subscriber and campaign data.

Preview template body

curl -u 'username:password' -X POST 'https://listmonk.mysite.com/api/templates/preview' \
  -d 'template_type=campaign' \
  -d 'body=<!DOCTYPE html><html><body>{{ template "content" . }}</body></html>'
Previews a template body without saving it. Authentication: Required
Permission: templates:get

Request Body

template_type
string
default:"campaign"
Template type: campaign or tx
body
string
required
Template HTML body to preview

Response

Returns rendered HTML preview.

Template Variables

Templates support Go template syntax with the following variables:

Campaign Templates

.Campaign
object
.Subscriber
object

Transactional Templates

.Tx
object

Template Functions

{{ TrackLink "https://example.com" }} - Creates a tracked link
TrackView
function
{{ TrackView }} - Inserts a tracking pixel
UnsubscribeURL
function
{{ UnsubscribeURL }} - Generates unsubscribe URL
ManageURL
function
{{ ManageURL }} - Generates subscription management URL
OptinURL
function
{{ OptinURL }} - Generates opt-in confirmation URL
Date
function
{{ Date "2006-01-02" }} - Formats current date

Build docs developers (and LLMs) love