Mailchimp 使用 php 和 drupal 8 向列表中的现有成员添加标签

Mailchimp add tags to existing member in a list with php and drupal 8

在将成员添加到列表后,我想在 Drupal 8 的 mailchimp 列表中为该成员添加一个标签。我用 PHP.

根据我在以下位置找到的信息: https://mailchimp.com/developer/guides/organize-contacts-with-tags/#label-a-contact-with-a-tag

以下代码有效:

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

但是下面的代码给出了 400 错误请求错误...

$mailchimp->lists->updateListMemberTags($list_id, $subscriber_hash, [
   "tags" => [
     "name" => "my_new_tag",
     "status" => "active"
   ]
]);

错误:

GuzzleHttp\Exception\ClientException:客户端错误:POST https://***.api.mailchimp.com/3.0/lists/***/members/***/tags 导致 400 Bad Request 响应:{“type”:“http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/”,“title”:“无效资源” ,"GuzzleHttp\Exception\RequestException::create() 中的统计信息(截断...)(/home/d8/drupal-project/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php 的第 113 行)。

=> https://mailchimp.com/developer/guides/marketing-api-conventions/#error-glossary

list_id 是正确的,hash 是正确的,但是向 mailchimp 列表中的现有成员添加了标签不工作。

文档不是很清楚。 "name" 和 "status" 必须是一个数组。 这是有道理的......但没有很好的记录。

$mailchimp->lists->updateListMemberTags($list_id, $subscriber_hash, [
   "tags" => [
     ["name" => "my_new_tag", "status" => "active"]
   ]
]);