GETList templates/api/v1/templatesGETGet a template/api/v1/templates/{templateId}POSTCreate a template/api/v1/templatesPATCHUpdate a template/api/v1/templates/{templateId}DELETEDelete a template/api/v1/templates/{templateId}POSTTest a template/api/v1/templates/{templateId}/test-sendGETBrowse the gallery/api/v1/template-galleryGETGet a gallery design/api/v1/template-gallery/{galleryTemplateId}POSTRender without sending/api/v1/render
What a template is, over HTTP
A template is an HTML file. There is no layout around it: whatever you send is what recipients receive, which also means the unsubscribe link has to be in your own markup — see Merge Tags Cheat Sheet.The template gallery
Writing 150 lines of email HTML by hand, correctly, is a bad use of anyone's time — yours or an agent's. The gallery is a small set of models we maintain: they carry their unsubscribe link, their editable regions, and they have been checked against the clients that matter. You read one, you copy it, you edit your copy. Read only. There is no endpoint to add, change or delete a model: the gallery belongs to the product, not to an organization. It is the same for every key. Only published models are visible. A draft answers404, exactly like an id that does not
exist — you cannot tell the two apart, and that is deliberate.
An API key is still required, as on every /api/v1 route. It is not used to filter anything here:
the gallery is common to all organizations, so there is nothing to scope.
Starting a template from a model
POST /api/v1/templates takes galleryTemplateId instead of content. The server reads the
published model and copies its HTML, so you never move 150 lines through your own process.
| Field | In | Required | Description |
|---|---|---|---|
name | body | yes | 1 to 100 characters |
galleryTemplateId | body | yes* | The model to copy. Replaces content |
defaultSubject | body | no | Falls back to the model's subject when you leave it out |
galleryTemplateId or content — see below.
bash
curl -X POST -H "x-api-key: $AGENTMAIL_API_KEY" -H "content-type: application/json" \
-d '{"name": "August newsletter", "galleryTemplateId": "'"$GALLERY_TEMPLATE_ID"'"}' \
"https://www.agentsmail.io/api/v1/templates"This is a copy, not an inheritance. Your template holds its own HTML from the moment it is
created. Improve the model tomorrow, and nothing of yours changes; edit your template, and the
gallery is untouched. Nothing links the two afterwards — there is no "update from the model"
endpoint, and there is no way for us to change what you already have.
| Condition | Answer |
|---|---|
galleryTemplateId alone | 201 — the model's HTML is copied |
content alone | 201 — your HTML, merge tags converted |
| both together | 400 — two different documents, pick one |
| neither | 400 — a template needs a document |
galleryTemplateId unknown, or not published | 400 — the message names the parameter |
unsupportedTags, including ones we would otherwise translate: they stayed raw in your
document and will not be interpreted when the email is rendered. Gallery models are normally written
in our own {{...}} vocabulary, so this list is usually empty — but you are told when it is not,
rather than finding out in an inbox.