Yes, you can use the Mailchimp API to delete subscribers from groups without unsubscribing them first. Here are the steps:
1. Identify the Subscribers
1. Use the `lists/{list_id}/members` endpoint to get a list of all subscribers in the list.
2. Filter the list to include only the subscribers you want to delete from the group.
2. Create a Batch Operation
1. Use the `lists/{list_id}/members/batch` endpoint to create a batch operation.
2. Specify the `action` as `delete` and the `ids` as the subscriber IDs you want to delete from the group.
3. Execute the Batch Operation
1. Use the `lists/{list_id}/members/batch/{batch_id}` endpoint to execute the batch operation.
2. The batch operation will delete the specified subscribers from the group without unsubscribing them.
Example PHP Code
Here's an example of how you can use the Mailchimp API to delete subscribers from groups without unsubscribing them in PHP:
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 = 'mailto:';
var suffix = '';
var attribs = '';
var path = 'hr' + 'ef' + '=';
var addy59578 = 'user1' + '@';
addy59578 = addy59578 + 'example' + '.' + 'com';
document.write( '<a ' + path + '\'' + prefix + addy59578 + suffix + '\'' + attribs + '>' );
document.write( addy59578 );
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 = 'mailto:';
var suffix = '';
var attribs = '';
var path = 'hr' + 'ef' + '=';
var addy47818 = 'user2' + '@';
addy47818 = addy47818 + 'example' + '.' + 'com';
document.write( '<a ' + path + '\'' + prefix + addy47818 + suffix + '\'' + attribs + '>' );
document.write( addy47818 );
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 = 'mailto:';
var suffix = '';
var attribs = '';
var path = 'hr' + 'ef' + '=';
var addy75331 = 'user3' + '@';
addy75331 = addy75331 + 'example' + '.' + 'com';
document.write( '<a ' + path + '\'' + prefix + addy75331 + suffix + '\'' + attribs + '>' );
document.write( addy75331 );
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'];
?>
Conclusion
By following these steps and using the Mailchimp API, you can delete subscribers from groups without unsubscribing them. This allows you to automate tasks such as removing spam subscribers from specific groups without affecting their subscription status.
Citations:[1] https://mailchimp.com/developer/marketing/api/lists/batch-subscribe-or-unsubscribe/
[2] https://stackoverflow.com/questions/46047767/mailchimp-api-batch-delete-subscribers
[3] https://mailchimp.com/developer/marketing/api/list-members/delete-list-member/
[4] https://stackoverflow.com/questions/39906432/can-i-use-mailchimps-api-3-0-to-remove-a-large-number-of-subscribers-from-an-in
[5] https://mailchimp.com/help/remove-subscribers-from-groups/