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

  • PATCH /api/v1/templates/{id} used to fail whenever the payload left out subject, returning a 400 that named a template_version constraint the caller had no way to know about. Every partial update was affected, so a script that only wanted to rename a template or swap its tags had to send the subject back unchanged. A PATCH now touches only the fields it sends.

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

Everything that has shipped

Private beta

See the next one land

Beta members get the release note in the same batch email that opens their account.