Skip to content
Last updated

Send campaigns using the Send API

Here we will cover the basics on how to create the input payload of a Send API POST request. For full information on the available functionalities of the Send API v3.1, please visit the dedicated section of our API guides and the API reference. For the purposes of this guide the examples provided will focus on Send API v3.1.

The input payload must always start with the Messages array. In it you can set up multiple message objects and / or multiple recipients of the same message object, depending on your needs.

To group messages into a campaign, set the campaign name for each message with the CustomCampaign property.

In addition, if you don’t want your contacts to receive multiple messages that are part of the same campaign, set the DeduplicateCampaign property to 1.

The standard requirements for sending a message with the Send API are to set:

  • A sender - with the From object
  • A recipient - with the To, Cc and Bcc objects
  • A subject line - with the Subject property
  • Email content - for this you have a couple of options:
  • A saved email template - with the TemplateID property
  • Content added directly into the payload via the TextPart, HtmlPart properties
# This call sends a message to one recipient within a campaign blocking multiple messages to same recipient
curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3.1/send \
	-H 'Content-Type: application/json' \
	-d '{
		"Messages":[
				{
						"From": {
								"Email": "pilot@mailjet.com",
								"Name": "Mailjet Pilot"
						},
						"To": [
								{
										"Email": "passenger1@mailjet.com",
										"Name": "passenger 1"
								}
						],
						"Subject": "Your email flight plan!",
						"TextPart": "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
						"HTMLPart": "<h3>Dear passenger 1, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />May the delivery force be with you!",
						"CustomCampaign": "SendAPI_campaign",
						"DeduplicateCampaign": true
				}
		]
	}'