4

Is it possible to actually delete a contact from mailjet?

Their contact API doc doesn't even list delete as a supported action.

from mailjet_rest import Client

mailjet = Client(auth=(MAILJET_API_KEY, MAILJET_API_SECRET), version='v3')
mailjet.contact.delete(<contact-id>).json()
{'ErrorInfo': '', 'ErrorMessage': 'Operation not allowed', 'StatusCode': 401}

I am interested in removing a contact, not a list recipient, and hence this question is not a duplicate of How can i delete a contact from a list with the mailjet api and php?.

Dušan Maďar
  • 9,269
  • 5
  • 49
  • 64

3 Answers3

5

The API reference does not yet seem to be updated with the DELETE method, but under API guides there seems to be information on how to delete contacts:

Retrieve a Contact

To delete a contact, you must first identify its presence in the contact database of your account.

Use GET /contact/$CONTACT_EMAIL to do it.

curl -s \
    -X GET \
    --user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
    https://api.mailjet.com/v3/REST/contact/$CONTACT_EMAIL 

Delete the Contact

Use the {contact_ID} you retrieved to DELETE the contact with the /v4/contacts/{contact_ID} endpoint. When the deletion is successful, the API will return a 200 OK status. Any other response will indicate that the deletion was not successfully processed.

curl -s \
    -X DELETE \
    --user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
    https://api.mailjet.com/v4/contacts/{contact_ID} \

NB: this is a /v4 endpoint, not /v3

Joundill
  • 6,828
  • 12
  • 36
  • 50
alisspers
  • 336
  • 3
  • 4
  • 1
    It's important to keep in mind, that this operation is not permanent, so your service should also take care to not use contact email in further transactional emails. API guide states: *The deletion of a contact does not prevent you from re-uploading the same contact in the future. If you are using an external database to sync contacts with your Mailjet contact database, please make sure to simultaneously remove the contacts from it as well.* – oxfn Oct 23 '19 at 20:51
2

With the right to be deleted and GDPR imminent, I would also be interested in this. Their support team has said it is not possible and you would have to contact them so they can manually delete contacts?!

Dušan Maďar
  • 9,269
  • 5
  • 49
  • 64
0

In Python, use a simple delete request

import requests
public_api_key = 'YOUR PUBLIC MAILJET KEY'
private_api_key = ''YOUR PRIVATE MAILJET KEY''
id = 'ID OF CONTACT'

url = 'https://api.mailjet.com/v4/contacts/'+id

x = requests.delete(url, auth = (api_key, api_secret))

print(x.status_code)
Keyul
  • 729
  • 1
  • 8
  • 20