Templates
Fetch templates created on MailerSend and other relevant information.
Get templates
Retrieve the account templates using this GET
request:
GET https://api.mailersend.com/v1/templates
Request parameters
Query parameter | Type | Required | Limitations | Details |
---|---|---|---|---|
domain_id | string | no | ||
page | int | no | ||
limit | int | no | Min: 10 , Max: 100 | Default: 25 |
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
// Get all templates of an account
$mailersend->template->getAll();
// Get all templates of a domain
$mailersend->template->getAll('domain_id');
// Get page 2 of templates with 20 records per page
$mailersend->template->getAll('domain_id', 2, 20);
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.template.list({
domain_id: "domain_id"
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
from mailersend import templates
api_key = "API key here"
mailer = templates.NewTemplate(api_key)
mailer.get_templates()
package main
import (
"context"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
var APIKey = "Api Key Here"
func main() {
// Create an instance of the mailersend client
ms := mailersend.NewMailersend(APIKey)
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
options := &mailersend.ListTemplateOptions{
Page: 1,
Limit: 25,
}
_, _, err := ms.Template.List(ctx, options)
if err != nil {
log.Fatal(err)
}
}
import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailersend.sdk.templates.TemplateItem;
import com.mailersend.sdk.templates.TemplatesList;
public void getTemplatesList() {
MailerSend ms = new MailerSend();
ms.setToken("mailersend token");
try {
TemplatesList list = ms.templates().getTemplates();
for (TemplateItem item : list.templates) {
System.out.println(item.id);
System.out.println(item.name);
}
} catch (MailerSendException e) {
e.printStackTrace();
}
}
require "mailersend-ruby"
ms_templates = Mailersend::Templates.new
ms_templates.list(domain_id: "aax455lll", page: 1, limit: 10)
Responses
Valid
Response Code: 200 OK
Response Headers:
content-type: application/json
{
"data": [
{
"id": "x8emy5o5world01w",
"name": "Signup email",
"type": "template type",
"image_path": "https://link.com/images/image.jpg",
"created_at": "2020-06-10 10:09:56",
},
{
"id": "x8emy5o5world01x",
"name": "Premium subscription",
"type": "template type",
"image_path": "https://link.com/images/image.jpg",
"created_at": "2020-06-10 10:09:56",
},
{
"id": "x8emy5o5world01y",
"name": "Newsletter",
"type": "template type",
"image_path": "https://link.com/images/image.jpg",
"created_at": "2020-06-10 10:09:56",
},
],
"links": {
"first": "https:\/\/www.mailersend.io\/api\/v1\/templates?page=1",
"last": "https:\/\/www.mailersend.io\/api\/v1\/templates?page=1",
"prev": null,
"next": null
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 1,
"path": "https:\/\/www.mailersend.io\/api\/v1\/templates",
"per_page": 25,
"to": 3,
"total": 3
}
}
Get a single template
Retrieve the information of a single template, its category, domain, and stats using this GET
request:
GET https://api.mailersend.com/v1/templates/{template_id}
Request parameters
URL parameter | Type | Required | Limitations | Details |
---|---|---|---|---|
template_id | string | yes |
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->template->find('template_id');
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.template.single("domain_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
from mailersend import templates
api_key = "API key here"
mailer = templates.NewTemplate(api_key)
template_id = 1234
mailer.get_template_by_id()
package main
import (
"context"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
var APIKey = "Api Key Here"
func main() {
// Create an instance of the mailersend client
ms := mailersend.NewMailersend(APIKey)
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
templateID := "template-id"
_, _, err := ms.Template.Get(ctx, templateID)
if err != nil {
log.Fatal(err)
}
}
import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.MailerSendResponse;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailersend.sdk.templates.Template;
import com.mailersend.sdk.templates.TemplateItem;
import com.mailersend.sdk.templates.TemplatesList;
public void getTemplate() {
MailerSend ms = new MailerSend();
ms.setToken("mailersend token");
try {
Template template = ms.templates().getTemplate("template id");
System.out.println(template.id);
System.out.println(template.name);
System.out.println(template.imagePath);
} catch (MailerSendException e) {
e.printStackTrace();
}
}
require "mailersend-ruby"
ms_templates = Mailersend::Templates.new
ms_templates.single(template_id: "id124")
Responses
Valid
{
"data": {
"id": "x8emy5o5world01w",
"name": "libero",
"type": "html",
"image_path": "http://mailersend.com/images/templates/placeholder.png",
"personalization": {
"name": "",
"elements": [
{
"name": "",
"price": ""
}
],
"license_key": "",
"account_name": "",
"product_name": "",
"renew_button": "",
"expiration_date": ""
},
"created_at": "2021-06-22T15:38:51.000000Z",
"category": {
"id": "5genxmqlgozlyvk7",
"name": "aut"
},
"domain": {
"id": "1jreeo",
"name": "domain.com",
...,
"domain_settings": {
...
},
"totals": {
"hard_bounced": 25,
"soft_bounced": 40,
"sent": 231,
"delivered": 109
}
},
"template_stats": {
"total": 0,
"queued": 0,
"sent": 0,
"rejected": 0,
"delivered": 0,
"last_email_sent_at": null
}
}
}
Error
Response Code: 404 Not Found
Delete a template
Delete a template with this DELETE
request:
DELETE https://api.mailersend.com/v1/templates/{template_id}
Request parameters
URL parameter | Type | Required | Limitations | Details |
---|---|---|---|---|
template_id | string | yes |
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->template->delete('template_id');
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.template.single("domain_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
from mailersend import templates
api_key = "API key here"
mailer = templates.NewTemplate(api_key)
template_id = 1234
mailer.delete_template()
package main
import (
"context"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
var APIKey = "Api Key Here"
func main() {
// Create an instance of the mailersend client
ms := mailersend.NewMailersend(APIKey)
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
templateID := "template-id"
_, err := ms.Template.Delete(ctx, templateID)
if err != nil {
log.Fatal(err)
}
}
import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.MailerSendResponse;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailersend.sdk.templates.Template;
import com.mailersend.sdk.templates.TemplateItem;
import com.mailersend.sdk.templates.TemplatesList;
public void deleteTemplate() {
MailerSend ms = new MailerSend();
ms.setToken("mailersend token");
try {
MailerSendResponse response = ms.templates().deleteTemplate("template id");
System.out.println(response.responseStatusCode);
} catch (MailerSendException e) {
e.printStackTrace();
}
}
require "mailersend-ruby"
ms_templates = Mailersend::Templates.new
ms_templates.delete(template_id: "id124")
Responses
Valid
Response Code: 200 OK
Response Body: [EMPTY]
Error
Response Code: 404 Not Found