« Back to Documentation Overview

listBatchUnsubscribe – v1.1

 listBatchUnsubscribe(string apikey, string id, array emails, boolean delete_member, boolean send_goodbye, boolean send_notify)

Unsubscribe a batch of email addresses to a list

List Related
apikey a valid API Key for your user account. Get by calling Get by visiting your API dashboard
id the list id to connect to. Get by calling lists()
emails array of email addresses to unsubscribe
delete_member flag to completely delete the member from your list instead of just unsubscribing, default to false
send_goodbye flag to send the goodbye email to the email addresses, defaults to true
send_notify flag to send the unsubscribe notification email to the address defined in the list email notification settings, defaults to false
struct Array of result counts and any errors that occurred
Returned Fields
integersuccess_countNumber of email addresses that were succesfully added/updated
integererror_countNumber of email addresses that failed during addition/updating
arrayerrorsArray of error structs. Each error struct will contain "code", "message", and "email"

Examples (1)

download example code

[1] mcapi_listBatchUnsubscribe.php

  1. <?php
  2. /**
  3. This Example shows how to run a Batch Unsubscribe on a List using the MCAPI.php
  4. class and do some basic error checking or handle the return values.
  5. **/
  6. require_once 'inc/MCAPI.class.php';
  7. require_once 'inc/config.inc.php'; //contains apikey
  9. $api = new MCAPI($apikey);
  11. $emails = array($my_email, $boss_man_email);
  12. $delete = false; //don't completely remove the emails
  13. $bye = true; // yes, send a goodbye email
  14. $notify = false; // no, don't tell me I did this
  16. $vals = $api->listBatchUnsubscribe($listId, $emails, $delete, $bye, $notify);
  18. if ($api->errorCode){
  19. // an api error occurred
  20. echo "code:".$api->errorCode."\n";
  21. echo "msg :".$api->errorMessage."\n";
  22. } else {
  23. echo "success:".$vals['success_count']."\n";
  24. echo "errors:".$vals['error_count']."\n";
  25. foreach($vals['errors'] as $val){
  26. echo "\t*".$val['email']. " failed\n";
  27. echo "\tcode:".$val['code']."\n";
  28. echo "\tmsg :".$val['message']."\n\n";
  29. }
  30. }
  31. ?>