I'm trying to use the DrewM\MailChimp PHP wrapper to batch update my MailChimp subscriber list. The main thing I'm trying to achieve is to sync the cover start and cover end dates with my already existing list. Here is my code:
$MailChimp = new MailChimp('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXX');
$Batch = $MailChimp->new_batch();
$list_id = "XXXXXXXXXX";
$orders = get_posts(array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'post_type' => 'shop_order',
'post_status' => 'wc-completed'
));
$body = array();
foreach($orders as $order) {
$data = new WC_Order($order->ID);
$meta = get_post_meta($order->ID);
$email_address = $data->get_billing_email();
$subscriber_hash = md5(strtolower($email_address));
// Cover Start Date Conversion
$cover_start_date = $meta['coverstart'][0];
$cover_start_date = DateTime::createFromFormat('d/m/Y', $cover_start_date);
$cover_start = $cover_start_date->format('Y/m/d');
// Cover End Date Conversion
$cover_end_date = DateTime::createFromFormat('d/m/Y', $meta['coverstart'][0]);
$cover_end_date->modify('-1 day');
$cover_end_date->modify('+1 year');
$cover_end = $cover_end_date->format('Y/m/d');
$body[] = array(
'email_address' => $email_address,
'status' => 'subscribed',
'merge_fields' => [
'FNAME' => $data->get_billing_first_name(),
'LNAME' => $data->get_billing_last_name(),
'COVERSTART' => $cover_start,
'COVEREND' => $cover_end,
]
);
}
$Batch->patch("op1", "lists/$list_id/members", $body);
$Batch->execute();
$status = $Batch->check_status();
print_r($status);
I seem to get a 100% error rate and can only assume I'm doing it completely wrong. A little guidance would be much appreciated!
Here are the errors from the MailChimp API:
[{"status_code":405,"operation_id":"B0","response":"{\"type\":\"http:\/\/developer.mailchimp.com\/documentation\/mailchimp\/guides\/error-glossary\/\",\"title\":\"Method Not Allowed\",\"status\":405,\"detail\":\"The requested method and resource are not compatible. See the Allow header for this resource's available methods.\",\"instance\":\"\"}"},{"status_code":405,"operation_id":"B1","response":"{\"type\":\"http:\/\/developer.mailchimp.com\/documentation\/mailchimp\/guides\/error-glossary\/\",\"title\":\"Method Not Allowed\",\"status\":405,\"detail\":\"The requested method and resource are not compatible. See the Allow header for this resource's available methods.\",\"instance\":\"\"}"},{"status_code":405,"operation_id":"B2","response":"{\"type\":\"http:\/\/developer.mailchimp.com\/documentation\/mailchimp\/guides\/error-glossary\/\",\"title\":\"Method Not Allowed\",\"status\":405,\"detail\":\"The requested method and resource are not compatible. See the Allow header for this resource's available methods.\",\"instance\":\"\"}"},{"status_code":405,"operation_id":"B3","response":"{\"type\":\"http:\/\/developer.mailchimp.com\/documentation\/mailchimp\/guides\/error-glossary\/\",\"title\":\"Method Not Allowed\",\"status\":405,\"detail\":\"The requested method and resource are not compatible. See the Allow header for this resource's available methods.\",\"instance\":\"\"}"},{"status_code":405,"operation_id":"B4","response":"{\"type\":\"http:\/\/developer.mailchimp.com\/documentation\/mailchimp\/guides\/error-glossary\/\",\"title\":\"Method Not Allowed\",\"status\":405,\"detail\":\"The requested method and resource are not compatible. See the Allow header for this resource's available methods.\",\"instance\":\"\"}"},{"status_code":405,"operation_id":"B5",