mailchimp-api icon indicating copy to clipboard operation
mailchimp-api copied to clipboard

Mailchimp Batch bulk update tags not working with PUT method

Open ashwindas77 opened this issue 3 years ago • 1 comments

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

ashwindas77 avatar May 15 '21 06:05 ashwindas77

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.

tuxfamily avatar Sep 07 '23 12:09 tuxfamily