I would like to add a tag to a member in a mailchimp list in Drupal 8 after adding the member to the list. I use PHP.
Based upon the info I found at: https://mailchimp.com/developer/guides/organize-contacts-with-tags/#label-a-contact-with-a-tag
Below code is working:
$response_tags = $mailchimp->lists->getListMemberTags($list_id, $subscriber_hash);
\Drupal::logger('mailchimp_get_tags')->notice('<pre><code>' . print_r($response_tags, TRUE) . '</code></pre>');
stdClass Object
(
[tags] => Array
(
[0] => stdClass Object
(
[id] => ****
[name] => 1_year
[date_added] => 2020-09-30T14:09:29+00:00
)
)
[total_items] => 1
)
But below code is giving 400 bad request error ...
$mailchimp->lists->updateListMemberTags($list_id, $subscriber_hash, [
"tags" => [
"name" => "my_new_tag",
"status" => "active"
]
]);
Error:
GuzzleHttp\Exception\ClientException: Client error: POST https://***.api.mailchimp.com/3.0/lists/***/members/***/tags resulted in a 400 Bad Request response: {"type":" http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ ","title":"Invalid Resource","stat (truncated...) in GuzzleHttp\Exception\RequestException::create() (line 113 of /home/d8/drupal-project/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php).
=> https://mailchimp.com/developer/guides/marketing-api-conventions/#error-glossary
The list_id is correct, the hash is correct but adding a tag to an existing member in the mailchimp list is not working.
The documentation is not very clear. "name" and "status" must be an array. That makes sense ... but it is not well documented.
$mailchimp->lists->updateListMemberTags($list_id, $subscriber_hash, [
"tags" => [
["name" => "my_new_tag", "status" => "active"]
]
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With