Templates
On this page:
- Get all templates
- Get a specific template
- Add a template
- Update a template
- Delete a template
- Error handling
These endpoints manage campaign templates. For transactional email templates, see Transactional emails.
Set MAILCOACH_API_URL and MAILCOACH_TOKEN as shown in Authentication. See the API reference for complete schemas.
Get all templates
curl "$MAILCOACH_API_URL/templates" \ -H "Authorization: Bearer $MAILCOACH_TOKEN" \ -H 'Accept: application/json'
Results are paginated. Search by name with ?filter[search]=newsletter. Sort by name or updated_at, for example ?sort=-updated_at for most recently updated first.
Get a specific template
Use the template’s UUID, not a numeric database ID:
curl "$MAILCOACH_API_URL/templates/11ce123b-57c4-429b-9840-c79f8047d8aa" \ -H "Authorization: Bearer $MAILCOACH_TOKEN" \ -H 'Accept: application/json'
The response contains the template under data, including uuid, name, html, structured_html, created_at and updated_at.
Add a template
Only name is required. You can also supply html and structured_html.
curl -X POST "$MAILCOACH_API_URL/templates" \ -H "Authorization: Bearer $MAILCOACH_TOKEN" \ -H 'Accept: application/json' \ -H 'Content-Type: application/json' \ -d '{"name":"Newsletter template","html":"<html><body><p>Newsletter</p></body></html>"}'
The response contains the new template under data. Use its uuid as template_uuid when creating a campaign.
Update a template
Include name when updating, along with the content you want to change.
curl -X PUT "$MAILCOACH_API_URL/templates/11ce123b-57c4-429b-9840-c79f8047d8aa" \ -H "Authorization: Bearer $MAILCOACH_TOKEN" \ -H 'Accept: application/json' \ -H 'Content-Type: application/json' \ -d '{"name":"Updated newsletter template","html":"<html><body><p>Updated newsletter</p></body></html>"}'
The response contains the updated template under data.
Delete a template
curl -X DELETE "$MAILCOACH_API_URL/templates/11ce123b-57c4-429b-9840-c79f8047d8aa" \ -H "Authorization: Bearer $MAILCOACH_TOKEN" \ -H 'Accept: application/json'
A successful deletion returns an empty 204 response.
Error handling
See common errors and retry guidance. A 204 response is successful and has no JSON body.