API docs

Introduction

Welcome to our documentation.

All the listed endpoints in this documentation can be used for your integration.

Currently we are working hard on improving API and the documentation.

If you have any questions, notes, bug reports or any other concerns, please feel free to write us [email protected]

# Base URL
https://api.templid.com/v1

Authentication

All requests to the API must be authenticated using Bearer token authentication.

To get your token, go to your Dashboard -> Tokens and generate a new token or use existing one.

# Following header values must be
# set to authenticate API request
Authorization: Bearer YOUR_TOKEN_HERE

Endpoints

Use the endpoints listed below to interact with the API.

POST

/templates/{templateId}/render

Render template with your dynamic data. Pass the arguments in the JSON body.

Request example:

curl -X POST "https://api.templid.com/v1/templates/{templateId}/render" \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-H "Content-type: application/json" \
-d '{
      "name": "John Doe",
      "amount": 44.99
    }'

Response example:

{
  "subject": "John Doe, we have received your order",
  "html": "<h1>Hello John Doe</h1><p>Your due amount is: $44.99</p>",
  "text": "Hello John Doe\n\nYour due amount is: $44.99"
}
POST

/templates/{templateId}/send/{integrationId}

To send your email template to one or multiple recipients, you can utilize SMTP integration.

How does SMTP integration works?

  1. In your dashboard, create an SMTP integration.
  2. Ensure you have a template set up in your dashboard.
  3. Using API you can send POST request to the designated endpoint. In the URL, specify the template ID and the integration ID. In the request body, include the sender's details and at least one recipient. Dynamic variables can also be added to your template if you need to render it with dynamic data.
  4. After a successful API call, an immediate response will be received. The emails will be queued and sent in the background, effectively reducing latency in your application.

How send email with PDF attachments?

You can use SMTP integration to send emails and attach your existing PDF templates to the email.

  1. Create PDF template in you dashboard.
  2. When making API request, add "attachments" key with array of objects next to the recipient in your JSON body.
  3. Attachment object must contain "id" key. This should be an "id" of your PDF template you've created in step 1.
  4. You can also add "filename" key to specify the name of the file that will be attached to the email.
  5. In case you want to render the PDF template with dynamic data, you can add "variables" key with an object of variables.

You can specify multiple attachments to single email.

Note: single email can have maximum of 20 attachments.

Using variables in the request body

When sending emails, you can set three different types of variables: global, recipient, and attachment.

Variables are optional, and you can use them only if you need to render your template with dynamic data. Here is an explanation of how to use them:

  • If you set only global variables, it will be used to replace values in the email template and attachments.
  • If you set recipient variables, it will be used to replace values in the email template and attachments for a specific recipient. So you can specify different values for each recipient.
  • If you set attachment variables, it will be used to replace values in the specific attachment. So you can specify different values for each attachment.
{
    "from": {...},
    "to": [
        {
            ..., // Other parameters
            "variables": {
                "recipient_level": "value" // <-- Recipient level variable
            },
            "attachmens": [
                {
                    ..., // Other parameters
                    "variables": {
                        "attachment_level": "value" // <-- Attachment level variable
                    }
                }
            ]
        }
    ],
    "variables": {
        "global_level": "value" // <-- Global level variable
    }
}

Child level variables override parent level variables in the following order:

  • Attachment level overrides recipient level and global level variables.
  • Recipient level overrides global level variables.

Let's take a look at the example below. We have a global level variable "name" with the value "Mike". This variable will be set in the email template for recipeint [email protected].

Also, we have a recipient level variable "name" with the value "John" for [email protected]. This variable will be set in the email template and attachment for this recipient.

Finally, we have an attachment level variable "name" with the value "Tom" for [email protected]. This variable will be set only in the attachment for this recipient.

{
    "from": {...},
    "to": [
        {
            "email": "[email protected]",
            "variables": {
                "name": "John"
            },
            "attachments": [
                {
                    "id": 123
                }
            ]
        },
        {
            "email": "[email protected]",
            "attachments": [
                {
                    "id": 123,
                    "variables": {
                        "name": "Tom"
                    },
                }
            ]
        },
    ],
    "variables": {
        "name": "Mike"
    }
}

Let's take a quick look at how nested variables work. In the example below, you can see that we are using a global level variable "user", and the value is an object.

To avoid repeating the same values for each child variables, we can override only the values we need. In this case, we are overriding "name" value for the first recipient. So the "company" value will be the same as a global level variable.

{
    "from": {...},
    "to": [
        {
            "email": "[email protected]",
            "variables": {
                "user": {
                    "name": "Jhon"
                }
            }
        }
    ],
    "variables": {
        "user": {
            "name": "Mike",
            "company": "Example company"
        }
    }
}

Request example:

curl -X POST "https://api.templid.com/v1/templates/{templateId}/send/{integrationId}" \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-H "Content-type: application/json" \
-d '{
        "from": {
            "email": "[email protected]",
            "name": "Example company"
        },
        "to": [
            {
                "email": "[email protected]",
                "name": "John Doe",
                "variables": {
                    "amount": 44.99
                }
            },
            {
                "email": "[email protected]",
                "name": "Jane Doe",
                "variables": {
                    "amount": 2569.73,
                    "manager_email": "[email protected]"
                },
                "attachments": [
                    {
                        "id": 39,
                        "filename": "order-confirmation.pdf",
                        "variables": {
                            "order": {
                                "id": 12345,
                                "date": "2023-09-25",
                                "payment_method": "Card"
                            }
                        }
                    },
                    {
                        "id": 40,
                        "filename": "terms-and-conditions.pdf",
                    }
                ]
            }
        ],
        "variables": {
            "manager_email": "[email protected]"
        }
    }'

Response example:

{
    "status": "success",
    "message": "Emails was put to the queue. We are sending your messages."
}

Templating docs

Introduction

We are rendering templates using Twig template engine. So you can use any syntax described in their documentation.

To be able to use our API, you must have at least one template created in your dashboard.

We mainly work with HTML or plain text templates, but you can apply to any text format.

Below you can see a general example:

<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>My template</title>
    </head>
    <body>
        <h1>Contact form request from web</h1>

        <p>Name: {{ name }}</p>
        <p>Email: {{ email }}</p>

        <p><b>Topics:</b></p>
        <ul>
            {% for topic in topics %}
            <li>{{ topic }}</li>
            {% endfor %}
        </ul>

        {% if text %}
        <p>Text:</p>
        <p><i>{{ text }}</i></p>
        {% endif %}
    </body>
</html>

How to create a PDF template

All the PDF templates are generated from HTML.

  1. Go to your dashboard
  2. On the left-side menu, click "Templates"
    Side menu Templates
  3. Next, click on "Add new template"
    Add new template button
  4. Select "PDF template" under the "Template type"
    Select type - PDF template
  5. Now you need to select "Editor type". Here, you have two options:
    1. Pre-built components - this option lets you create the tempalte with simple builder. You can learn more about this feature in our blog article on how to build the template with content blocks.
    2. Custom HTML - this option allows you to design a template using your own HTML code. You can use any HTML and CSS code you want. This gives you more flexibility and full control of your template.
    Select template editor type
  6. In this example, we will select "Custom HTML". First, type a name for your template. This name will be visible only to you in your dashboard.
    Add template name
  7. Finally, create your template. Feel free to use any HTML and CSS code you prefer. Also, you can use dynamic variables as needed. Once your template is prepared, click the "Save new template" button.
    Add template HTML
  8. In the list of templates, you will find your recently created template To render the template with dynamic data, you need to use our API You can copy the template ID from the list and use it to specify the template in the API URL.
    Template ID in the list