goodEgg goodEgg - 1 year ago 213
PHP Question

MailChimp API 3.0 Batch update - Always pending, total_operations:0

Trying to update a batch of emails. I think I've tried every way to do this, but my use of DrewM's MailChimp wrapper only returns the following


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

And so on. No errors, but no operations!

Essentially, my code looks like this, where
stores all the emails in an array.


$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",
'status' => 'subscribed',

} 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',
$result = $Batch->execute(); // Send the request (not working I guess)
$MailChimp->new_batch($batch_id); // Now get results
$result = $Batch->check_status();

If anyone can see what I'm not seeing, I'll be very grateful!

Answer Source

Problem solved. After talking with a rep at MailChimp, he helped to find two major problems.

Instead of using a POST method, he said to use PUT, when working with already existing emails. POST is best used for adding emails, while PUT can add and update emails.

So, change




Secondly, after successfully sending requests and getting errors in the $result, he found they were 405 errors and told me to add the md5 hash to my emails.

So, change

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


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

And they sent me a MailChimp stocking cap for being a good sport :-)

Veni. Vidi. Vici.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download