Send with a template
Pass template.id and variables instead of html.
Send a published template by naming it and passing its variables. PostShiba renders the published version for each message.
Before you start
- Publish the template. Drafts cannot send over REST.
- Have an API key and a verified sending domain. A Send only key can send templates. Listing or editing templates over the API needs Full access.
Send the template
- POST to
/api/v1/emails, or to/api/v1/teams/:obfuscated_team_id/clusters/:obfuscated_cluster_id/sendsto target one cluster. - Set
template.idto the alias or the public id. - Pass
template.variables. Do not passhtmlortext.
send-template.sh
1curl -sS -X POST \
2 -H 'Authorization: Bearer YOUR_API_KEY' \
3 -H 'Content-Type: application/json' \
4 -d '{
5 "from": "hello@mail.example.com",
6 "to": ["you@example.com"],
7 "template": {
8 "id": "welcome",
9 "variables": {
10 "name": "Ada",
11 "body": "Your account is ready.",
12 "action_url": "https://example.com/start"
13 }
14 },
15 "unique_args": {"campaign_id": "cmp_123"}
16 }' \
17 https://app.postshiba.com/api/v1/emails
response.json
1{
2 "queued": true,
3 "message_id": "abc@capsule.test",
4 "from": "hello@mail.example.com",
5 "to": ["you@example.com"],
6 "subject": "Hi Ada",
7 "unique_args": {"campaign_id": "cmp_123"}
8}
A body wrapped as {"send": {...}} works the same way.
Override template fields
| Request field | Effect |
|---|---|
from |
Replaces the template From. Omit it to use the template From. |
subject |
Replaces the rendered subject. The override is not Liquid. |
reply_to |
Replaces the template Reply-To. |
unique_args, attachments, headers, and tenant work as on any send. See Unique args, Attachments, and Custom headers.
Template errors
Each returns 422 with {"error": "invalid", "field": "template"}.
| Message | Cause |
|---|---|
is unknown |
No template has that alias or id on your team. |
is not published |
The template has never been published. |
cannot be combined with html or text |
The request passed html or text with template. |
| A Liquid error | The published version failed to render with these variables. |
Other send failures are on Errors.