Skip to content

Create Template Content

Endpoint: POST https://api.mailjet.com/v1/REST/templates/:id/contents

Once you have created your template, you should use this endpoint to add content to your template. You will need to specify the template ID and include either MJML, HTML or plain text.

URL Parameters: id = The ID of the template.

Body Parameters

NameTypeDescription
AuthorstringThe name of the person or entity creating the template content.
NamestringThe name of the template content.
LocalestringRequired. Specifies the locale (language and region) for the template content. See the full list of accepted locales.
MJMLPartstringThe MJML code for the template. Either MJMLPart, TextPart or HTMLPart must be provided.
HTMLPartstringThe HTML code for the template. Either MJMLPart, TextPart or HTMLPart must be provided.
TextPartstringThe plain text version of the template content. Either MJMLPart, TextPart or HTMLPart must be provided.
Headersjson stringAdditional headers for the template in JSON format. This can be used to set custom headers for the email content.

Example Request:

curl --request POST \
  --url https://api.mailjet.com/v1/rest/templates/27/contents \
  --header 'Authorization: Bearer 612d5125131d406081abb9cd2afdc4e3' \
  --header 'Content-Type: application/json' \
  --data '{
      "Name": "First content",
      "Headers": {
          "Subject": "Welcome to Mailjet",
          "From": "MyCompany <info@mycompany.com>",
          "Reply-To": "",
          "SenderName": "My Company",
          "SenderEmail": "info@mycompany.com"
      },
      "HTMLPart": "<!doctype html><html><body><p>May the delivery force be with you!</p></body></html>",
      "TextPart": "Dear passenger, welcome to Mailjet! May the delivery force be with you!",
      "Locale": "en_US"
}'

status code 201

Response Data Field Structure

NameTypeDescription
IDintegerThis is the ID of the version of your content.
TemplateIDintegerThis is the ID of the template.
ContentTypestring"D", "P" or "A". Always "D" when created.
Authorstring or nullThe name of the person or entity creating the template content.
NamestringThe name of the template content.
IsLockedbooleanIf this field is true (locked), the template content cannot be edited.
LocalestringSpecifies the locale (language and region) for the template content.
MJMLPartstring or nullThe MJML code for the template.
HTMLPartstring or nullThe HTML code for the template.
TextPartstring or nullThe plain text version of the template content.
Headersjson stringHeaders for the template in JSON format.
CreatedAtDate RFC3339The date and time when the template was created.
UpdatedAtDate RFC3339The date and time when the template was last updated.

Example API Response

{
	"ID": 16,
	"OrganisationID": 2,
	"UserID": 2,
	"TemplateID": 1,
	"ContentType": "D",
	"Author": "Toto",
	"Name": "New Name",
	"IsLocked": true,
	"Locale": "fr_FR",
	"Headers": {
		"Subject": "Welcome to Mailjet",
		"From": "MyCompany <info@mycompany.com>",
		"Reply-To": "",
		"SenderName": "My Company",
		"SenderEmail": "info@mycompany.com"
	},
	"HTMLPart": "<!doctype html><html><body><p>May the delivery force be with you!</p></body></html>",
	"TextPart": "Dear passenger, welcome to Mailjet! May the delivery force be with you!",
	"CreatedAt": "2024-04-19T15:19:08.322718Z",
	"UpdatedAt": "2024-04-19T15:19:08.322718Z"
}