2016-07-07 35 views
0

試圖更新一批電子郵件。我想我已經想盡辦法做到這一點,但我使用的DrewM's MailChimp wrapper只返回以下$result內容:MailChimp API 3.0批量更新 - 始終處於待處理狀態,total_operations:0

Array ([id] => 1234abcd [status] => pending [total_operations] => 0 [finished_operations] => 0 

等。沒有錯誤,但沒有操作!

本質上,我的代碼如下所示,其中$emails將所有電子郵件存儲在一個數組中。

include("MailChimp.php"); 
include("Batch.php"); 

$list_id = "1234abcd"; 

use \DrewM\MailChimp\MailChimp; 
use \DrewM\MailChimp\Batch; 
$apiKey = 'aslkjf84983hg84938h89gd-us13'; 

if(!isset($emails)){ // If not sending bulk requests 
    $MailChimp = new MailChimp($apiKey); 
    $subscriber_hash = $MailChimp->subscriberHash($email); 
    $result = $MailChimp->patch("lists/$list_id/members/$subscriber_hash", 
     array(
      'status' => 'subscribed', 
     ) 
    ); 

/* SENDING BATCH OF EMAILS */ 
} else if($emails){ 
    $MailChimp = new MailChimp($apiKey); 
    $Batch  = $MailChimp->new_batch(); 
    $i = 1; 
    foreach($emails as &$value){ 
     $Batch->post("op".$i, "lists/$list_id/members", [ 
      'email_address' => $value, 
      'status'  => 'subscribed', 
     ]); 
     $i++; 
    } 
    $result = $Batch->execute(); // Send the request (not working I guess) 
    $MailChimp->new_batch($batch_id); // Now get results 
    $result = $Batch->check_status(); 
    print_r($result); 
} 

如果有人能看到我沒有看到的東西,我將非常感激!

回答

1

問題已解決。在與MailChimp的代表交談後,他幫助找到了兩個主要問題。

與其使用POST方法,他說在使用已有的電子郵件時使用PUT。 POST最好用於添加電子郵件,而PUT可以添加和更新電子郵件。

所以,改變

$Batch->post 

$Batch->put 

其次,在成功發送請求並獲得在$result錯誤,他發現他們是405錯誤,並告訴我到md5哈希添加到我的電子郵件。

所以,改變

$Batch->post("op".$i, "lists/$list_id/members", [ ... 

$subscriber_hash = $MailChimp->subscriberHash($value); 
$Batch->put("op$i", "lists/$list_id/members/$subscriber_hash", [ ... 

他們給我發了一個MailChimp絨線帽,作爲一個很好的運動:-)

VENI。 VIDI。維西。

相關問題