Whenever you have contacts subscribed to multiple lists, it’s tedious to unsubscribe them from every single one, in case they don’t want to receive any marketing emails. You would also want an easy way to prevent a sending in case you accidentally subscribed a contact to a new list.
This is why Campaign Exclusion List was created - it helps you prevent an accidental sending of a marketing campaign to users. You can add users to this exclusion list and they will be automatically blocked from receiving marketing emails.
Contacts in the exclusion list will still be able to receive messages sent via the Send API.
To add a single contact to the exclusion list, you simply need to modify its IsExcludedFromCampaigns property to true with a PUT /contact/{contact_id_or_email}.
# Call to add contact to exclusion list
curl -s \
-X PUT \
--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
https://api.mailjet.com/v3/REST/contact/$ID_OR_EMAIL \
-H 'Content-Type: application/json' \
-d '{
"IsExcludedFromCampaigns":"true"
}'{
"Count": 1,
"Data": [
{
"CreatedAt": "2014-06-10T08:30:32Z",
"DeliveredCount": "",
"Email": "Mister@mailjet.com",
"ExclusionFromCampaignsUpdatedAt": "2014-06-10T08:47:28Z",
"ID": "1",
"IsExcludedFromCampaigns": "true",
"IsOptInPending": "false",
"IsSpamComplaining": "false",
"LastActivityAt": "2014-06-10T08:47:28Z",
"LastUpdateAt": "2014-12-31T11:00:46Z",
"Name": "John",
"UnsubscribedAt": "",
"UnsubscribedBy": ""
}
],
"Total": 1
}In case you want to exclude multiple contacts, you have a couple of options to do that:
- Using
/contact/managemanycontacts - Using
/csvimport
When doing the POST call, simply set the IsExcludedFromCampaigns to true for the contacts you want to exclude.
# Create : Manage the details of a Contact.
curl -s \
-X POST \
--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
https://api.mailjet.com/v3/REST/contact/managemanycontacts \
-H 'Content-Type: application/json' \
-d '{
"Contacts":[
{
"Email": "jimsmith@example.com",
"Name": "Jim",
"IsExcludedFromCampaigns": true,
"Properties": {
"Property1": "value",
"Property2": "value2"
}
},
{
"Email": "janetdoe@example.com",
"Name": "Janet",
"IsExcludedFromCampaigns": true,
"Properties": {
"Property1": "value",
"Property2": "value2"
}
}
]
}'Using the CSV Upload methodology, you can upload a list of contacts to add them to or remove them from the exclusion list. To do that, you need to set the Method property to excludemarketing or includemarketing, respectively.
The JSON payload sent to /csvimport should NOT contain the ContactsListID property. If it does, the following error will appear: MJ08 Property ContactsList is invalid: Exclusion of contacts from marketing campaign is a global status and can not be applied to a list
# Create: A wrapper for the CSV importer
curl -s \
-X POST \
--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
https://api.mailjet.com/v3/REST/csvimport \
-H 'Content-Type: application/json' \
-d '{
"DataID":"$ID_DATA",
"Method":"excludemarketing"
}'