The Content API supports two types of authentication:
- Basic Authentication
- Bearer Token
Basic Authentication requires a Mailjet API Key and Secret Key which can be found on your API Key Management page in Mailjet.
Once authenticated, you can create a Bearer token with a POST to https://api.mailjet.com/v1/REST/tokens. You can assign permissions to the token. Consult the full list of permissions.
Creating a template is a two-step process.
- Use the Template Creation endpoint
POST https://api.mailjet.com/v1/REST/templatesto specify the name, description, and purpose of your template.
Be sure to retrieve the ID of your template. This is the equivalent of creating an envelope for your template content.
- Once your template has been created, use the Template Content endpoint
POST https://api.mailjet.com/v1/REST/templates/:id/contentsto add content to your template by specifying the ID of your template. Content includes body text, images, links and more.
If you would like to revert your template content to a previous version, here are the necessary steps:
Ensure you have the ID of the template you want to revert. *You can retrieve the template ID using this endpoint:
GET https://api.mailjet.com/v1/REST/templatesRetrieve the versions of the template content:
- Use the following endpoint to get a list of all versions of the template content:
GET http://api.mailjet.com/v1/REST/templates/:id/contents. - Replace
:idwith your template ID.
Review the retrieved versions and identify the one to which you would like to revert.
Copy the
Headersas well asHTMLPart,MJMLPartand/orTextPartof the desired version and use the following endpoint to update the template:PUT http://api.mailjet.com/v1/REST/templates/:id/contents/types/:content_type.
- Replace
:idwith your template ID and:content_typewith the appropriate content type.
Accepted content types are: D (Draft) P (Published)
Note: A template with a content type of D (Draft) cannot be sent until its content is published using the following endpoint: POST https://api.mailjet.com/v1/REST/templates/:id/contents/publish.
You've created your template using the Content API. Now you'd like to send it using Mailjet's Send API. To do this, you must:
- Ensure your template is published
- If you created an HTML template via API or created a template using the Mailjet drag-and-drop editor: the template must be published either through the UI or via the API.
- Use this endpoint to publish via API:
POST https://api.mailjet.com/v1/REST/templates/:id/contents/publish.
- If you created an MJML template via API (Edit Mode
4): the template must be published in the Mailjet UI.
- Retrieve Your Template's External ID
- The
ExternalIDcan be obtained with the following endpoint:GET https://api.mailjet.com/v1/REST/templates.
Once your template is publshed and you have its ExternalID, you can proceed to the Send API to send your email.
Uploading images for use in the Mailjet image gallery is a two-part process:
- Upload the image content and meta data using this endpoint:
POST https://api.mailjet.com/v1/data/images - Upload a thumbnail for the image using this endpoint:
PUT https://api.mailjet.com/v1/data/images/:id/:content_type
When you upload a thumbnail, you will need to specify the image ID and specify a content type of thumbnail. If you do not upload a thumbnail, the image will appear in the Mailjet image gallery with a generic placeholder.