API docs
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
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
Use the endpoints listed below to interact with the API.
Render template with your dynamic data. Pass the arguments in the JSON body.
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
}'
{
"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"
}
To send your email template to one or multiple recipients, you can utilize SMTP integration.
You can use SMTP integration to send emails and attach your existing PDF templates to the email.
You can specify multiple attachments to single email.
Note: single email can have maximum of 20 attachments.
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:
{
"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:
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"
}
}
}
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]"
}
}'
{
"status": "success",
"message": "Emails was put to the queue. We are sending your messages."
}
Templating docs
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>
All the PDF templates are generated from HTML.