Creating an email template via the Content API is a two-step process:
Create the Template: This step involves creating the basic structure of the template, including its name, description and purpose.
Add Content to the Template: Once the template is ready, the next step is to add content to the template. This content could include text, images, and variables needed for personalizing the email.
If you would like your template to be visible in the Mailjet user interface, you will need to assign a purpose to your template.
Mailjet has four types of templates:
- Marketing: Templates used for promotional content, such as newsletters, sales announcements, and special offers. These are sent using Campaigns.
- Transactional: Templates for operational emails, like order confirmations, shipping notifications, and password resets. These are sent via API or SMTP.
- Automation: Templates designed for automated email workflows, such as welcome emails, birthday messages, and follow-ups. These are sent within an automation workflow.
- Opt-in: Templates for double opt-in emails for your Mailjet forms. These are sent automatically when a contact fills out your form.
Each category corresponds to a purpose in the Content API:
marketingtransactionalautomationopt-in
Assigning a purpose is optional. However, if you do not assign a purpose to your template, the template will not be available in the UI.
It is also important to assign a template purpose to ensure proper access control as token permissions are aligned with the purposes of the templates.
For example, if a template has a purpose of transactional, the user must have a token with transactional permissions to access it.
There are four edit modes in Mailjet:
1= Drag-and-drop builder (cannot be created via API)2= HTML builder3= Saved Section builder (cannot be created via API)4= MJML builder
Default Value The default edit mode is 2 (HTML builder).
Edit Mode 2 (HTML builder) and Edit Mode 4 (MJML builder) can be used to create and edit templates via API.
When using Edit Mode 4, the template must be coded in MJML and published in the user interface before it can be sent.
Edit Mode 1 (Drag-and-drop builder) and Edit Mode 3 (Saved Section builder) will be visible when retrieving a list of templates using this endpoint: GET https://api.mailjet.com/v1/REST/templates.
As long as the content of the template has been been published, you can use a template created in Edit Mode 1 (Drag-and-drop builder) to send via API.
You can always publish the content of a template at this endpoint: POST https://api.mailjet.com/v1/REST/templates/:id/contents/publish.
Creating or editing templates in Edit Mode 1 or Edit Mode 3 is at your own risk. These templates may break in the UI, and Mailjet will not be able to repair them. Please ensure you follow these guidelines to avoid any issues with your templates.
When creating template content, a locale is required in order to be able to save and send your template.
en_US fr_FR da_DK de_DE es_ES nl_NL it_IT sv_SE pt_BR pt_PT ru_RU ja_JP lv_LV is_IS ro_RO el_GR ar_AR sk_SK cs_CZ pl_PL zh_CN
If the purpose of your template is automation, only the following locales are accepted:
en_USfr_frde_DEìt_ITes_ES
Template content is categorized by content types. There are three types:
D = Draft: Template content is always created with this status.P = Published: Content that has been published will have this status.A = Autosave: Indicates that an autosave has occurred in the user interface.
By default, the content type is set to D.
You cannot directly ,modify the content type field via API, but you can search by content type.
To send your template, it must have a content type of P, meaning it has been published. To publish your template, use its ID with a POST request to this endpoint: https://api.mailjet.com/v1/REST/templates/:id/contents/publish.
Since the Content API always publishes the latest draft, you may want to search by content type D before publishing to ensure you are publishing the correct content.
Additionally, Mailjet stores up to 5 versions of content per content type for a single template. If you need to revert to a previous version, you can also search by content type. For details on reverting to a previous version of template content, refer to our FAQ.