Skip to content

Single Contact Management

Create a contact

You can create new contacts with a POST request on the contact resource.

Example

curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/contact \
	-H 'Content-Type: application/json' \
	-d '{
      "IsExcludedFromCampaigns":"true",
      "Name":"New Contact",
      "Email":"passenger@mailjet.com"
	}'

API Response

{
	"Count": 1,
	"Data": [
		{
			"IsExcludedFromCampaigns": true,
			"Name": "New Contact",
			"CreatedAt": "2018-01-01T00:00:00",
			"DeliveredCount": 10,
			"Email": "passenger@mailjet.com",
			"ExclusionFromCampaignsUpdatedAt": "2018-01-01T00:00:00",
			"ID": 123456789,
			"IsOptInPending": false,
			"IsSpamComplaining": false,
			"LastActivityAt": "2018-01-01T00:00:00",
			"LastUpdateAt": "2018-01-01T00:00:00",
			"UnsubscribedAt": "2018-01-01T00:00:00",
			"UnsubscribedBy": "2018-01-01T00:00:00"
		}
	],
	"Total": 1
}

Manage Contact Properties

If you want to add more granular details about your contacts, Mailjet provides the capability to add custom data to contacts. This additional data can help you personalize the emails you are sending, and allows you to target specific sections of your customers using segmentation.

The addition of custom data starts with the definition of the extra information to store with the contacts (It could be for example the country the contacts live in, how old the contacts are, their current income, the value of their purchases on your site...) and how this data will be stored (string, number, boolean...).

To define custom contact data, perform a POST on /contactmetadata with the following properties:

Name : the name of the custom data field DataType : the type of data that is being stored (this can be either a str, int, float, datetime or bool) NameSpace : this can be either static or historic (legacy)

Info

Keep in mind that the accepted formats for a datetime data type are Unix timestamp (e.g. 1514764800)and RFC3339 (e.g. 2018-01-01T00:00:00)

Example

curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/contactmetadata \
	-H 'Content-Type: application/json' \
	-d '{
      "Datatype":"str",
      "Name":"first_name",
      "NameSpace":"static"
	}'

API Response

{
	"Count": 1,
	"Data": [
		{
			"Datatype": "str",
			"ID": 4321,
			"Name": "first_name",
			"NameSpace": "static"
		}
	],
	"Total": 1
}

To add, edit or update the data saved for a specific contact, do a PUT request on /contactdata/{contact_ID or contact_email}.

Example

curl -s \
	-X PUT \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/contactdata/$contact_ID \
	-H 'Content-Type: application/json' \
	-d '{
      "Data":[
        {
          "Name":"first_name",
          "Value":"John"
        }
      ]
	}'

API Response

{
	"Count": 1,
	"Data": [
		{
			"Data": [
				{}
			],
			"ContactID": 123456,
			"ID": 123456
		}
	],
	"Total": 1
}

Contact data can also be added for multiple contacts at the same time by using the bulk contact management resources.

Create a contact list

Contact lists are created with POST request on the /contactslist

Example

curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/contactslist \
	-H 'Content-Type: application/json' \
	-d '{
      "Name":"my_contactslist"
	}'

API Response

{
	"Count": 1,
	"Data": [
		{
			"Name": "my_contactslist",
			"Address": "abcdef123",
			"CreatedAt": "2018-01-01T00:00:00",
			"ID": 123456,
			"SubscriberCount": 111
		}
	],
	"Total": 1
}

Add a contact to a contact list

To add a contact to a list, you need to create a new list recipient with a POST request on the /listrecipient resource. You can specify the contact by either providing the contact ID (in ContactID) or email address (in ContactAlt), as well as the list with either the list ID (in ListID) or the list name (in ListAlt).

Example

curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/listrecipient \
	-H 'Content-Type: application/json' \
	-d '{
      "IsUnsubscribed":"true",
      "ContactID":"987654321",
      "ContactAlt":"passenger@mailjet.com",
      "ListID":"123456",
      "ListAlt":"abcdef123"
	}'

API Response

{
	"Count": 1,
	"Data": [
		{
			"IsUnsubscribed": true,
			"ContactID": 987654321,
			"ID": 1234567890,
			"IsActive": true,
			"ListID": 123456,
			"ListName": "abcdef123",
			"SubscribedAt": "2018-01-01T00:00:00",
			"UnsubscribedAt": "2018-01-01T00:00:00"
		}
	],
	"Total": 1
}