Skip to content

API / Templates

Method Endpoint Description
GET /api/templates Retrieve all templates
GET /api/templates/{template_id} Retrieve a template
GET /api/templates/{template_id}/preview Retrieve template HTML preview
POST /api/templates Create a template
POST /api/templates/preview Render and preview a template
PUT /api/templates/{template_id} Update a template
PUT /api/templates/{template_id}/default Set default template
DELETE /api/templates/{template_id} Delete a template

GET /api/templates

Retrieve all templates.

Example Request
curl -u "api_user:token" -X GET 'http://localhost:9000/api/templates'
Example Response
{
    "data": [
        {
            "id": 1,
            "created_at": "2020-03-14T17:36:41.288578+01:00",
            "updated_at": "2020-03-14T17:36:41.288578+01:00",
            "name": "Default template",
            "body": "{{ template \"content\" . }}",
            "type": "campaign",
            "is_default": true
        }
    ]
}

GET /api/templates/{template_id}

Retrieve a specific template.

Parameters
Name Type Required Description
template_id number Yes ID of the template to retrieve
Example Request
curl -u "api_user:token" -X GET 'http://localhost:9000/api/templates/1'
Example Response
{
    "data": {
        "id": 1,
        "created_at": "2020-03-14T17:36:41.288578+01:00",
        "updated_at": "2020-03-14T17:36:41.288578+01:00",
        "name": "Default template",
        "body": "{{ template \"content\" . }}",
        "type": "campaign",
        "is_default": true
    }
}

GET /api/templates/{template_id}/preview

Retrieve the HTML preview of a template.

Parameters
Name Type Required Description
template_id number Yes ID of the template to preview
Example Request
curl -u "api_user:token" -X GET 'http://localhost:9000/api/templates/1/preview'
Example Response
<p>Hi there</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et elit ac elit sollicitudin condimentum non a magna.
    Sed tempor mauris in facilisis vehicula. Aenean nisl urna, accumsan ac tincidunt vitae, interdum cursus massa.
    Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam varius turpis et turpis lacinia placerat.
    Aenean id ligula a orci lacinia blandit at eu felis. Phasellus vel lobortis lacus. Suspendisse leo elit, luctus sed
    erat ut, venenatis fermentum ipsum. Donec bibendum neque quis.</p>

<h3>Sub heading</h3>
<p>Nam luctus dui non placerat mattis. Morbi non accumsan orci, vel interdum urna. Duis faucibus id nunc ut euismod.
    Curabitur et eros id erat feugiat fringilla in eget neque. Aliquam accumsan cursus eros sed faucibus.</p>

<p>Here is a link to <a href="https://listmonk.app" target="_blank">listmonk</a>.</p>

POST /api/templates

Create a template.

Parameters
Name Type Required Description
name string Yes Name of the template
type string Yes Type of the template (campaign or tx)
subject string Subject line for the template (only for tx)
body string Yes HTML body of the template
Example Request
curl -u "api_user:token" -X POST 'http://localhost:9000/api/templates' \
-H 'Content-Type: application/json' \
-d '{
    "name": "New template",
    "type": "campaign",
    "subject": "Your Weekly Newsletter",
    "body": "<h1>Header</h1><p>Content goes here</p>"
}'
Example Response
{
    "data": [
        {
            "id": 1,
            "created_at": "2020-03-14T17:36:41.288578+01:00",
            "updated_at": "2020-03-14T17:36:41.288578+01:00",
            "name": "Default template",
            "body": "{{ template \"content\" . }}",
            "type": "campaign",
            "is_default": true
        }
    ]
}

PUT /api/templates/{template_id}

Update a template.

Refer to parameters from POST /api/templates


PUT /api/templates/{template_id}/default

Set a template as the default.

Parameters
Name Type Required Description
template_id number Yes ID of the template to set as default
Example Request
curl -u "api_user:token" -X PUT 'http://localhost:9000/api/templates/1/default'
Example Response
{
    "data": {
        "id": 1,
        "created_at": "2020-03-14T17:36:41.288578+01:00",
        "updated_at": "2020-03-14T17:36:41.288578+01:00",
        "name": "Default template",
        "body": "{{ template \"content\" . }}",
        "type": "campaign",
        "is_default": true
    }
}

DELETE /api/templates/{template_id}

Delete a template.

Parameters
Name Type Required Description
template_id number Yes ID of the template to delete
Example Request
curl -u "api_user:token" -X DELETE 'http://localhost:9000/api/templates/35'
Example Response
{
    "data": true
}