在阅读了许多具有相同问题的帖子并尝试了多种不同的方法来解决我的问题之后,我希望在您的帮助下在这里找到解决方案
我想从 Mailchimp 中的成员中删除标签,但是当我通过 WordPress 函数中的 API 执行此操作时,响应代码为 204
function post_to_third_party( $entry, $form ) {
$api = 'my_api';
$list_id = 'id_list';
$current_user = wp_get_current_user();
$email = $current_user->user_email;
$response = wp_remote_post(
'https://'. substr( $api, strpos( $api, '-') + 1 ) . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/' . md5( strtolower( $email ) ) . '/tags',
array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'user:'. $api )
),
'tags' => array(['name'=>'gomme','status'=>'inactive'])
)
);
error_log( 'gform_after_submission: response => ' . print_r( $response, true ) );
}
add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 );
在官方文档中https://mailchimp.com/developer/marketing/api/list-member-tags/ -> 添加或删除成员标签,说明可以更新/删除但每个帖子中都没有用户我读成功了
Mailchimps API 有效,我使用此代码添加和删除标签:
使用Mailchimps官方PHP SDK
$data = [
'tags' => [
[
'name' => 'name',
'status' => 'active'
],
[
'name' => 'Test22',
'status' => 'inactive'
]
]
];
$this->apiClient->lists->updateListMemberTags('abcdeg123', '[email protected]', $data);
您必须遵循准确的数组结构,否则API将不会添加或删除标签。有点奇怪的是,当发送不正确的数据结构时,api 没有发出任何错误。它只会报告格式错误的 JSON。