0

I use mailjet api to send newsletter, but i don't know how delete a contact from a list.

Please help me.

1 Answers1

0

I'm a developer evangelist here at Mailjet.

The relation between a contactlist and a contact is represented through the listrecipient entity. You can learn more about this in our guide, here:

To remove a contact from a list, you have two options: either DELETE this entity or unsubscribe the contact from the list. The second solution has the advantage to keep the contact's status in the list. It prevents to send unwanted emails to a contact, if for some reason you add it in the list again later.

First, do a GET request to retrieve the ID of the listrecipient entity. As described in our reference documentation, here, use the Contact and ContactsList filter. Once you have the ID, you can either run a DELETE request on it to permanently delete the contact in the list or set the IsUnsubscribed property to true to unsubscribe it.

arnaud.breton
  • 2,054
  • 1
  • 24
  • 39
  • Thank you for your answer, but i have another problem i can't get the ID of the listrecipient, there is my code: function getContact() { $mj = new Mailjet(); //$mj->listrecipient; $params = array( "method" => "GET", "ContactALT" => 'xxxxxxxx@gmail.com', "ListID" => '1', ); $mj->listrecipient($params); echo $mj->_response->Data[0]->ID; } the result is the ID of the listreciptient of the first contact. Thank's again. – – user3621100 Nov 14 '14 at 14:15
  • I found the solution To get the ID of the listrecipient entity i use this function: function getContact() { $mj = new Mailjet(); $params = array( "method" => "GET", "ContactsList" => 1, "ContactEmail" => 'xxxxxxxx@gmail.com', ); $mj->listrecipient($params); return $mj->_response->Data[0]->ID; } and to delete the contact from the list: function deleteContact($ID){ $mj = new Mailjet(); $params = array( "method" => "DELETE", "ID" => $ID, ); $result = $mj->listrecipient($params); } deleteContact(getContact()); Thank you arnaud – user3621100 Nov 14 '14 at 14:59
  • Very welcome, glad you managed to make it work. Best. – arnaud.breton Nov 14 '14 at 15:57