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
/api/v1/email-templates/previewcurl -X POST 'https://app.mailyte.com/api/v1/email-templates/preview' \
-H 'Authorization: Bearer mk_live_YOUR_API_KEY'const response = await fetch('https://app.mailyte.com/api/v1/email-templates/preview', {
method: 'POST',
headers: {
Authorization: 'Bearer mk_live_YOUR_API_KEY',
},
});
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"},
)
data = response.json()["data"]<?php
$response = Http::withToken('mk_live_YOUR_API_KEY')
->post('https://app.mailyte.com/api/v1/email-templates/preview');
$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"
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }Response
Success.
dataobjectobjectstringtemplate_previewsubjectstringThe subject with `{{ }}` substituted, as a real send would render it -- the preview runs the same renderer. NULL MEANS NONE: you supplied no `subject` to render, so there was nothing to give back. A subject you DID supply that renders away to nothing comes back as `""`, not null, so the two cases stay distinguishable -- which matters, because `""` usually means a `{{ }}` name you did not pass a value for.
htmlstringSubstituted values are HTML-escaped here and left raw in `subject` and `text`. NULL MEANS NONE -- no `html` was supplied to render -- and, as with `subject`, an empty render is `""` rather than null. This endpoint renders ONLY what you post: it does not load a stored template, so a request carrying just a `template_id` previews nothing and every content field here is null.
textstringThe rendered plain-text body. The REQUEST field for it is `plain_text`, not `text`: this endpoint validates `plain_text` and drops a `text` key, so posting `text` renders nothing and returns null here.
variablesarray<string>The `{{ }}` placeholder names found in the supplied content -- what an editor builds its sample-value form from. This field was called `tags` before, which in this same module means the caller's labels on a message; they are unrelated. Names, not values: a placeholder appears here whether or not you supplied a value for it.
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.