mailchimp-api
mailchimp-api copied to clipboard
Mailchimp Batch bulk update tags not working with PUT method
Hi,
I tried to bulk update mailchimp tags using batch method. I used put method to do the same. But it is not working.
Attaching my code snippet. Please help me out,
$Batch = $MailChimp->new_batch();
$list_id = "listID";
$tagsSelected = ['tagFromAPI 99','tagFromAPI 00'];
$Batch->put("op1", "lists/$list_id/members", [
'email_address' => '[email protected]',
'status_if_new' => 'subscribed',
'tags' => $tagsSelected,
'merge_fields' => [
'FNAME' => 'Jish3' ?: '',
'LNAME' => 'win' ?: '',
]
]);
$Batch->put("op2", "lists/$list_id/members", [
'email_address' => '[email protected]',
'status_if_new' => 'subscribed',
'tags' => $tagsSelected,
'merge_fields' => [
'FNAME' => 'Lax2' ?: '',
'LNAME' => 'Sav' ?: '',
]
]);
$Batch->put("op3", "lists/$list_id/members", [
'email_address' => '[email protected]',
'status_if_new' => 'subscribed',
'tags' => $tagsSelected,
'merge_fields' => [
'FNAME' => 'Lenity1' ?: '',
'LNAME' => 'Lancer' ?: '',
]
]);
$result = $Batch->execute();
$MailChimp->new_batch($batch_id);
$result = $Batch->check_status();
echo '<pre>';print_r($result);
According to the doc, here, the tags
field should look like this:
{"tags": [{"name": "Influencer", "status": "active"}]}
So your $tagsSelected
array should be something like this:
$tagsSelected = [
['name' => 'tagFromAPI 99', 'status' => 'active'],
['name' => 'tagFromAPI 00', 'status' => 'active']
]
(not tested)
This said, on update, don't forget to untag
with inactive
also.