Preview a rendered template
/api/v1/email-templates/previewRenders a template with the variables you supply and returns the result without sending anything. Worth calling in your own test suite: it is the cheapest way to catch a variable you renamed on one side and not the other.
Request body
subjectstringThe subject line to preview.
htmlstringThe HTML to preview, with
{{ tags }}.skeleton_htmlstringOptional, advanced. Your own HTML with
data-my-editon the parts people may change in the dashboard. We buildhtmlfrom it andcontent.source_template_keystringOptional. Make the template from one of our ready-made designs, by the design's key. We build
htmlfrom the design, your brand kit andcontent.contentobjectFor a template made from a design (
source_template_key) or fromskeleton_html: the text and images for each editable part, keyed by the part's name. Not used with plainhtml.layoutstringFor a template made from a design: which version of the design, for example
brandedorplain. A name the design does not have falls back to its default.show_company_namebooleanFor a template made from a design: show your company name at the top. Leave it out, or send null, to follow your brand kit.
plain_textstringPlain text to preview. With
plain: true, it is laid out exactly as a plain email is sent.plainbooleanSend
trueto previewplain_textas a plain email, exactly as it would be sent.variablesobjectSample values for the
{{ tags }}, like{"name": "Ada"}.emailandorganization_nameare filled for you.brandobjectOptional. Brand kit values to try before saving them (logo, colours, company name).
Request
/api/v1/email-templates/previewcurl -X POST 'https://app.mailyte.com/api/v1/email-templates/preview' \
-H 'Authorization: Bearer mk_live_YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"html": "<p>Hi {{name}}</p>",
"variables": {
"name": "Ada"
}
}'const response = await fetch('https://app.mailyte.com/api/v1/email-templates/preview', {
method: 'POST',
headers: {
Authorization: 'Bearer mk_live_YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"html": "<p>Hi {{name}}</p>",
"variables": {
"name": "Ada"
}
}),
});
const { data } = await response.json();import requests
response = requests.post(
"https://app.mailyte.com/api/v1/email-templates/preview",
headers={"Authorization": "Bearer mk_live_YOUR_API_KEY"},
json={
"html": "<p>Hi {{name}}</p>",
"variables": {
"name": "Ada"
}
},
)
data = response.json()["data"]<?php
$response = Http::withToken('mk_live_YOUR_API_KEY')
->post('https://app.mailyte.com/api/v1/email-templates/preview', [
'html' => '<p>Hi {{name}}</p>',
'variables' => [
'name' => 'Ada',
],
]);
$data = $response->json('data');require "net/http"
require "json"
uri = URI("https://app.mailyte.com/api/v1/email-templates/preview")
request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer mk_live_YOUR_API_KEY"
request["Content-Type"] = "application/json"
request.body = {
"html": "<p>Hi {{name}}</p>",
"variables": {
"name": "Ada"
}
}.to_json
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }Response
Success.
dataobjectobjectstringtemplate_previewsubjectstringThe subject with
{{ }}variables filled in, as a real send would show it. Null when you sent nosubject.""usually means a placeholder you gave no value for.htmlstringThe HTML with
{{ }}variables filled in; values are HTML-escaped here. Null when you sent nohtml. This endpoint previews only what you post: it does not load a saved template.textstringThe rendered plain-text body. The REQUEST field for it is
plain_text, nottext: this endpoint validatesplain_textand drops atextkey, so postingtextrenders nothing and returns null here.variablesarray<string>The
{{ }}placeholder names found in what you sent, whether or not you gave them values.
Returned inside the standard envelope.
Errors
| Status | When |
|---|---|
401 | The API key is missing, unknown, revoked or expired. All four answer identically, on purpose: distinguishing them would confirm which keys exist. |
403 | The key is valid but may not do this: it lacks the required scope, its IP allowlist does not include you, or this endpoint does not accept API keys. |
404 | No such resource in this organization. |
422 | The request was understood but the values were not acceptable. |
429 | Too many requests, or the organization has spent its sending allowance. `Retry-After` says how long to wait. |
Every status, with what causes it and what to do, is on the error reference.