Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon what are the best practices for managing large numbers of subscribers in Mailchimp using the API


what are the best practices for managing large numbers of subscribers in Mailchimp using the API


Managing large numbers of subscribers in Mailchimp using the API involves several best practices to ensure efficient and effective management. Here are some key considerations:

1. Batch Operations:

- Use Batch Operations: Mailchimp's API supports batch operations, which allow you to perform multiple operations at once. This can significantly improve performance when managing large numbers of subscribers[4].

2. API Rate Limiting:

- Monitor API Rate Limiting: Mailchimp's API has rate limits to prevent abuse. Monitor your API usage to avoid hitting these limits, which can result in errors and delays[3].

3. Subscriber Hashing:

- Use Subscriber Hashes: When managing subscribers, use subscriber hashes instead of email addresses. This ensures that you are operating on the correct subscriber records[4].

4. Error Handling:

- Handle Errors: When performing batch operations, handle errors properly to avoid failures and ensure that operations are executed correctly[4].

5. Segmentation:

- Use Segmentation: Segment your subscribers based on specific criteria to manage large numbers more efficiently. This allows you to target specific groups and reduce the number of operations needed[2].

6. API Documentation:

- Consult API Documentation: Familiarize yourself with Mailchimp's API documentation to understand the available endpoints and how to use them effectively[3].

7. Third-Party Libraries:

- Use Third-Party Libraries: Utilize third-party libraries, such as the DrewM MailChimp API wrapper, to simplify API interactions and improve performance[4].

8. Testing:

- Test Your Code: Thoroughly test your code to ensure that it works correctly and efficiently with large numbers of subscribers[4].

9. Monitoring:

- Monitor Your Operations: Monitor your operations to identify potential issues and optimize your workflow for better performance[4].

10. Best Practices:

- Follow Best Practices: Follow best practices for email marketing, such as creating valuable content and segmenting your audience, to ensure that your subscribers remain engaged and active[5].

By following these best practices, you can effectively manage large numbers of subscribers in Mailchimp using the API and ensure efficient and successful email marketing campaigns.

Citations:
[1] https://stackoverflow.com/questions/39906432/can-i-use-mailchimps-api-3-0-to-remove-a-large-number-of-subscribers-from-an-in
[2] https://www.merge.dev/blog/how-to-add-a-subscriber-and-more-with-the-mailchimp-api
[3] https://mailchimp.com/developer/marketing/api/
[4] https://stackoverflow.com/questions/46047767/mailchimp-api-batch-delete-subscribers
[5] https://www.linkedin.com/pulse/mastering-art-email-marketing-best-practices-mailchimp-zahidul-islam-1p8tc

Sample Code

Here are some sample code snippets for managing large numbers of subscribers in Mailchimp using the API:

1. Batch Operations:

php
<?php
require_once 'path/to/mailchimp-api/vendor/autoload.php';

use \DrewM\MailChimp\MailChimp;

// Initialize the Mailchimp API client
$mailchimp = new MailChimp(MAILCHIMP_API_KEY);
$mailchimp->setConfig(['server' => 'YOUR_SERVER_PREFIX']);

// Get the list ID
$listId = '**********';

// Get the subscriber IDs
$subscriberIds = array_map('md5', array_filter(array_map('strtolower', array_map('trim', array_map('explode', ',', '
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy86866 = '&#117;s&#101;r1' + '&#64;';
 addy86866 = addy86866 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy86866 + suffix + '\'' + attribs + '>' );
 document.write( addy86866 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy76264 = '&#117;s&#101;r2' + '&#64;';
 addy76264 = addy76264 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy76264 + suffix + '\'' + attribs + '>' );
 document.write( addy76264 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy99839 = '&#117;s&#101;r3' + '&#64;';
 addy99839 = addy99839 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy99839 + suffix + '\'' + attribs + '>' );
 document.write( addy99839 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>')))));

// Create a batch operation
$batch = $mailchimp->new_batch();
foreach ($subscriberIds as $subscriberId) {
    $batch->delete("op" . count($batch->operations), "lists/$listId/members/$subscriberId");
}

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

2. API Rate Limiting:

php
<?php
require_once 'path/to/mailchimp-api/vendor/autoload.php';

use \DrewM\MailChimp\MailChimp;

// Initialize the Mailchimp API client
$mailchimp = new MailChimp(MAILCHIMP_API_KEY);
$mailchimp->setConfig(['server' => 'YOUR_SERVER_PREFIX']);

// Get the list ID
$listId = '**********';

// Get the subscriber IDs
$subscriberIds = array_map('md5', array_filter(array_map('strtolower', array_map('trim', array_map('explode', ',', '
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy67987 = '&#117;s&#101;r1' + '&#64;';
 addy67987 = addy67987 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy67987 + suffix + '\'' + attribs + '>' );
 document.write( addy67987 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy45277 = '&#117;s&#101;r2' + '&#64;';
 addy45277 = addy45277 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy45277 + suffix + '\'' + attribs + '>' );
 document.write( addy45277 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy23777 = '&#117;s&#101;r3' + '&#64;';
 addy23777 = addy23777 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy23777 + suffix + '\'' + attribs + '>' );
 document.write( addy23777 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>')))));

// Monitor API usage
$apiUsage = $mailchimp->get_api_usage();
if ($apiUsage['rate_limit'] < 100) {
    // Perform operations within the rate limit
    foreach ($subscriberIds as $subscriberId) {
        $mailchimp->delete("lists/$listId/members/$subscriberId");
    }
} else {
    // Wait for the rate limit to reset
    sleep(60);
    // Perform operations within the rate limit
    foreach ($subscriberIds as $subscriberId) {
        $mailchimp->delete("lists/$listId/members/$subscriberId");
    }
}
?>

3. Subscriber Hashing:

php
<?php
require_once 'path/to/mailchimp-api/vendor/autoload.php';

use \DrewM\MailChimp\MailChimp;

// Initialize the Mailchimp API client
$mailchimp = new MailChimp(MAILCHIMP_API_KEY);
$mailchimp->setConfig(['server' => 'YOUR_SERVER_PREFIX']);

// Get the list ID
$listId = '**********';

// Get the subscriber IDs
$subscriberIds = array_map('md5', array_filter(array_map('strtolower', array_map('trim', array_map('explode', ',', '
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy65893 = '&#117;s&#101;r1' + '&#64;';
 addy65893 = addy65893 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy65893 + suffix + '\'' + attribs + '>' );
 document.write( addy65893 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy46922 = '&#117;s&#101;r2' + '&#64;';
 addy46922 = addy46922 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy46922 + suffix + '\'' + attribs + '>' );
 document.write( addy46922 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy35178 = '&#117;s&#101;r3' + '&#64;';
 addy35178 = addy35178 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy35178 + suffix + '\'' + attribs + '>' );
 document.write( addy35178 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>')))));

// Use subscriber hashes
foreach ($subscriberIds as $subscriberId) {
    $mailchimp->delete("lists/$listId/members/$subscriberId");
}
?>

4. Error Handling:

php
<?php
require_once 'path/to/mailchimp-api/vendor/autoload.php';

use \DrewM\MailChimp\MailChimp;

// Initialize the Mailchimp API client
$mailchimp = new MailChimp(MAILCHIMP_API_KEY);
$mailchimp->setConfig(['server' => 'YOUR_SERVER_PREFIX']);

// Get the list ID
$listId = '**********';

// Get the subscriber IDs
$subscriberIds = array_map('md5', array_filter(array_map('strtolower', array_map('trim', array_map('explode', ',', '
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy99209 = '&#117;s&#101;r1' + '&#64;';
 addy99209 = addy99209 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy99209 + suffix + '\'' + attribs + '>' );
 document.write( addy99209 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy62371 = '&#117;s&#101;r2' + '&#64;';
 addy62371 = addy62371 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy62371 + suffix + '\'' + attribs + '>' );
 document.write( addy62371 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy34224 = '&#117;s&#101;r3' + '&#64;';
 addy34224 = addy34224 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy34224 + suffix + '\'' + attribs + '>' );
 document.write( addy34224 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>')))));

// Handle errors
try {
    foreach ($subscriberIds as $subscriberId) {
        $mailchimp->delete("lists/$listId/members/$subscriberId");
    }
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
?>

5. Segmentation:

php
<?php
require_once 'path/to/mailchimp-api/vendor/autoload.php';

use \DrewM\MailChimp\MailChimp;

// Initialize the Mailchimp API client
$mailchimp = new MailChimp(MAILCHIMP_API_KEY);
$mailchimp->setConfig(['server' => 'YOUR_SERVER_PREFIX']);

// Get the list ID
$listId = '**********';

// Get the segment ID
$segmentId = '**********';

// Get the subscriber IDs
$subscriberIds = array_map('md5', array_filter(array_map('strtolower', array_map('trim', array_map('explode', ',', '
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy22 = '&#117;s&#101;r1' + '&#64;';
 addy22 = addy22 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy22 + suffix + '\'' + attribs + '>' );
 document.write( addy22 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy62985 = '&#117;s&#101;r2' + '&#64;';
 addy62985 = addy62985 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy62985 + suffix + '\'' + attribs + '>' );
 document.write( addy62985 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy60271 = '&#117;s&#101;r3' + '&#64;';
 addy60271 = addy60271 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy60271 + suffix + '\'' + attribs + '>' );
 document.write( addy60271 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>')))));

// Segment subscribers
$mailchimp->post("lists/$listId/segments/$segmentId/members", [
    'ids' => $subscriberIds,
]);
?>

6. API Documentation:

php
<?php
require_once 'path/to/mailchimp-api/vendor/autoload.php';

use \DrewM\MailChimp\MailChimp;

// Initialize the Mailchimp API client
$mailchimp = new MailChimp(MAILCHIMP_API_KEY);
$mailchimp->setConfig(['server' => 'YOUR_SERVER_PREFIX']);

// Get the list ID
$listId = '**********';

// Get the subscriber IDs
$subscriberIds = array_map('md5', array_filter(array_map('strtolower', array_map('trim', array_map('explode', ',', '
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy23185 = '&#117;s&#101;r1' + '&#64;';
 addy23185 = addy23185 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy23185 + suffix + '\'' + attribs + '>' );
 document.write( addy23185 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy40167 = '&#117;s&#101;r2' + '&#64;';
 addy40167 = addy40167 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy40167 + suffix + '\'' + attribs + '>' );
 document.write( addy40167 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy66985 = '&#117;s&#101;r3' + '&#64;';
 addy66985 = addy66985 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy66985 + suffix + '\'' + attribs + '>' );
 document.write( addy66985 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>')))));

// Use API documentation
$mailchimp->delete("lists/$listId/members/$subscriberId");
?>

7. Third-Party Libraries:

php
<?php
require_once 'path/to/mailchimp-api/vendor/autoload.php';

use \DrewM\MailChimp\MailChimp;

// Initialize the Mailchimp API client
$mailchimp = new MailChimp(MAILCHIMP_API_KEY);
$mailchimp->setConfig(['server' => 'YOUR_SERVER_PREFIX']);

// Get the list ID
$listId = '**********';

// Get the subscriber IDs
$subscriberIds = array_map('md5', array_filter(array_map('strtolower', array_map('trim', array_map('explode', ',', '
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy87715 = '&#117;s&#101;r1' + '&#64;';
 addy87715 = addy87715 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy87715 + suffix + '\'' + attribs + '>' );
 document.write( addy87715 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy20526 = '&#117;s&#101;r2' + '&#64;';
 addy20526 = addy20526 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy20526 + suffix + '\'' + attribs + '>' );
 document.write( addy20526 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy21266 = '&#117;s&#101;r3' + '&#64;';
 addy21266 = addy21266 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy21266 + suffix + '\'' + attribs + '>' );
 document.write( addy21266 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>')))));

// Use third-party libraries
$mailchimp->delete("lists/$listId/members/$subscriberId");
?>

8. Testing:

php
<?php
require_once 'path/to/mailchimp-api/vendor/autoload.php';

use \DrewM\MailChimp\MailChimp;

// Initialize the Mailchimp API client
$mailchimp = new MailChimp(MAILCHIMP_API_KEY);
$mailchimp->setConfig(['server' => 'YOUR_SERVER_PREFIX']);

// Get the list ID
$listId = '**********';

// Get the subscriber IDs
$subscriberIds = array_map('md5', array_filter(array_map('strtolower', array_map('trim', array_map('explode', ',', '
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy20680 = '&#117;s&#101;r1' + '&#64;';
 addy20680 = addy20680 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy20680 + suffix + '\'' + attribs + '>' );
 document.write( addy20680 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy94149 = '&#117;s&#101;r2' + '&#64;';
 addy94149 = addy94149 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy94149 + suffix + '\'' + attribs + '>' );
 document.write( addy94149 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy80434 = '&#117;s&#101;r3' + '&#64;';
 addy80434 = addy80434 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy80434 + suffix + '\'' + attribs + '>' );
 document.write( addy80434 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>')))));

// Test the code
foreach ($subscriberIds as $subscriberId) {
    $mailchimp->delete("lists/$listId/members/$subscriberId");
}
?>

9. Monitoring:

php
<?php
require_once 'path/to/mailchimp-api/vendor/autoload.php';

use \DrewM\MailChimp\MailChimp;

// Initialize the Mailchimp API client
$mailchimp = new MailChimp(MAILCHIMP_API_KEY);
$mailchimp->setConfig(['server' => 'YOUR_SERVER_PREFIX']);

// Get the list ID
$listId = '**********';

// Get the subscriber IDs
$subscriberIds = array_map('md5', array_filter(array_map('strtolower', array_map('trim', array_map('explode', ',', '
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy24448 = '&#117;s&#101;r1' + '&#64;';
 addy24448 = addy24448 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy24448 + suffix + '\'' + attribs + '>' );
 document.write( addy24448 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy96942 = '&#117;s&#101;r2' + '&#64;';
 addy96942 = addy96942 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy96942 + suffix + '\'' + attribs + '>' );
 document.write( addy96942 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy53275 = '&#117;s&#101;r3' + '&#64;';
 addy53275 = addy53275 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy53275 + suffix + '\'' + attribs + '>' );
 document.write( addy53275 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>')))));

// Monitor API usage
$apiUsage = $mailchimp->get_api_usage();
if ($apiUsage['rate_limit'] < 100) {
    // Perform operations within the rate limit
    foreach ($subscriberIds as $subscriberId) {
        $mailchimp->delete("lists/$listId/members/$subscriberId");
    }
} else {
    // Wait for the rate limit to reset
    sleep(60);
    // Perform operations within the rate limit
    foreach ($subscriberIds as $subscriberId) {
        $mailchimp->delete("lists/$listId/members/$subscriberId");
    }
}
?>

10. Best Practices:

php
<?php
require_once 'path/to/mailchimp-api/vendor/autoload.php';

use \DrewM\MailChimp\MailChimp;

// Initialize the Mailchimp API client
$mailchimp = new MailChimp(MAILCHIMP_API_KEY);
$mailchimp->setConfig(['server' => 'YOUR_SERVER_PREFIX']);

// Get the list ID
$listId = '**********';

// Get the subscriber IDs
$subscriberIds = array_map('md5', array_filter(array_map('strtolower', array_map('trim', array_map('explode', ',', '
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy32550 = '&#117;s&#101;r1' + '&#64;';
 addy32550 = addy32550 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy32550 + suffix + '\'' + attribs + '>' );
 document.write( addy32550 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy26352 = '&#117;s&#101;r2' + '&#64;';
 addy26352 = addy26352 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy26352 + suffix + '\'' + attribs + '>' );
 document.write( addy26352 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>, 
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy19299 = '&#117;s&#101;r3' + '&#64;';
 addy19299 = addy19299 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy19299 + suffix + '\'' + attribs + '>' );
 document.write( addy19299 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>')))));

// Follow best practices
foreach ($subscriberIds as $subscriberId) {
    $mailchimp->delete("lists/$listId/members/$subscriberId");
}
?>

These code snippets demonstrate how to manage large numbers of subscribers in Mailchimp using the API.