如何使用DrewM MailChimp Batch API?

时间:2017-06-27 13:27:49

标签: php mailchimp-api-v3.0

我尝试使用DrewM\MailChimp PHP包装器批量更新我的MailChimp订阅者列表。我试图实现的主要功能是将封面开始和封面结束日期与我现有的列表同步。这是我的代码:

$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);

我似乎得到了100%的错误率,并且只能假设我做错了。非常感谢一点指导!

以下是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",

0 个答案:

没有答案