Block templates over the API, with a validator and a real preview

Building an email from blocks is no longer dashboard-only work. Create or update a template with a document instead of bodyHtml and the server validates the blocks and compiles the HTML itself, so what gets stored is exactly what the blocks say.

Two endpoints, both read-only

POST /templates/validate checks a document and returns every problem in it at once, where saving an invalid one gives you a single 400. If you generate documents programmatically, that is the endpoint to build the loop around: one call tells you everything to fix rather than one thing per round trip.

POST /templates/preview renders unsaved HTML or blocks through the same path a real send uses. Both need only templates:read, because neither writes anything, which means a key that is allowed to look at your templates is allowed to check them without also being allowed to change them.

Preview shows you what you did not write

Because it composes the way a send does, the preview includes the parts the pipeline adds: the unsubscribe block marketing mail gains, and the effect of the channel floor. Preview a transactional template as a campaign and the unsubscribe still appears, because a campaign is always marketing whatever the template says.

Neither of those is something a preview rendered in your own interface can tell you, which is the whole reason this is a server endpoint rather than a client-side render.

Null and omitted are different requests

One asymmetry to know about on update: a document of null ejects the template to raw HTML, while omitting the field leaves the authoring mode alone. A client that strips nulls before serialising can therefore never eject, and will look like it is ignoring you. If you mean to eject, send the null explicitly.

Also in this release

  • A PATCH to /api/v1/templates/{id} touches only the fields it sends, so a script can rename a template or swap its tags without sending the subject back.

Related: Validate a template document, Preview a template, Templates

Everything that has shipped

Free trial

See the next one land

Everything listed here is live the day it is listed. Start a trial and use it.

7-day free trial. Pick a plan, add a card, cancel before the trial ends and you won't be charged. 1,000 contacts and 5,000 sends during the trial.