Templates store subjects and bodies once, so your services send a template id and a few variables instead of whole HTML documents. Reference one when sending by setting content.template_id.
Create template
POST/v1/templates
Creates a stored template that can be referenced by content.template_id in transmissions.
At least one of html or text must be provided.
Body
namestringRequiredUnique template name.
subjectstringRequiredSubject template.
htmlstringOne ofHTML content.
textstringOne ofText content.
Returns
idstringTemplate id (UUID).
namestringTemplate name.
subjectstringSubject template.
htmlstringHTML content.
textstringText content.
created_atstringISO timestamp.
updated_atstringISO timestamp.
curl -X POST "https://api.sendlib.com/v1/templates" \
-H "Authorization: Bearer $SENDLIB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Welcome Email",
"subject": "Welcome, {{.first_name}}",
"html": "<h1>Hi {{.first_name}}</h1>",
"text": "Hi {{.first_name}}"
}'{
"id": "…",
"name": "…",
"subject": "…",
"html": "…",
"text": "…",
"created_at": "…",
"updated_at": "…"
}curl "https://api.sendlib.com/v1/templates" \
-H "Authorization: Bearer $SENDLIB_API_KEY"{
"error": {
"message": "Missing or invalid API key."
}
}Get template
GET/v1/templates/{id}
Fetch a single template.
Path parameters
idstringRequiredTemplate id.
curl "https://api.sendlib.com/v1/templates/TEMPLATE_ID" \
-H "Authorization: Bearer $SENDLIB_API_KEY"{
"error": {
"message": "Missing or invalid API key."
}
}Update template
PATCH/v1/templates/{id}
Updates template fields (partial update).
Path parameters
idstringRequiredTemplate id.
curl -X PATCH "https://api.sendlib.com/v1/templates/TEMPLATE_ID" \
-H "Authorization: Bearer $SENDLIB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"subject": "Updated subject"}'{
"error": {
"message": "The request body is not valid JSON or is missing a required field."
}
}Delete template
DELETE/v1/templates/{id}
Deletes a stored template.
Path parameters
idstringRequiredTemplate id.
curl -X DELETE "https://api.sendlib.com/v1/templates/TEMPLATE_ID" \
-H "Authorization: Bearer $SENDLIB_API_KEY"{
"error": {
"message": "Missing or invalid API key."
}
}Use a template in a transmission
{
"recipients": [{"email": "user@example.com"}],
"content": {
"template_id": "TEMPLATE_ID",
"substitution_data": {"first_name": "Ada"}
}
}Next
- Sending: Transmissions
- Debugging payload issues: Errors
