简体   繁体   中英

Mailchimp API : Batch Delete subscribers

Is there any reference to the PHP warpper that I can use to perform batch delete subscribers. we have around 100k+ spam subscribers in Mailchimp list that we need to delete using batch delete.

Thanks

There is no official PHP wrapper for API v3, but you can use third-party wrappers such as this one from DrewM . He has provided good documentation on how to use it.

Here is an example of how you can create a batch operation to delete (not unsubscribe) each spam address in the $spamAddresses array. Of course, you'd have to populate the array first.

<?php
include('mailchimp-api-master/src/MailChimp.php');
include('mailchimp-api-master/src/Batch.php');

use \DrewM\MailChimp\MailChimp;
use \DrewM\MailChimp\Batch;

$apiKey = '********************************';
$listId = '**********';

$spamAddresses = [];

$MailChimp = new MailChimp($apiKey);
$Batch = $MailChimp->new_batch();

//Loop through array of spam addresses.
for($i = 0; $i < sizeof($spamAddresses); $i++){
    $subscriberHash = $MailChimp->subscriberHash($spamAddresses[$i]);
    $Batch->delete("op$i", "lists/$listId/members/$subscriberHash");
}

//Execute batch operation.
$result = $Batch->execute();
echo $result['id'];
?>

Make sure to grab the batch ID that's stored in $result['id'] if you want to check up on the status of the batch operation later, as DrewM's example shows in his documentation:

$MailChimp->new_batch($batch_id);
$result = $Batch->check_status();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM