wordpress Mailchimp API:从成员中删除现有标签是不可能的

e37o9pze  于 12个月前  发布在  WordPress
关注(0)|答案(1)|浏览(91)

在阅读了许多相同问题的帖子,并尝试了许多不同的方法来解决我的问题后,我希望在您的帮助下找到解决方案
我想从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/->添加或删除成员标签,解释有可能更新/删除,但没有用户在我读到的每一篇文章都成功

myzjeezk

myzjeezk1#

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。

相关问题