在阅读了许多相同问题的帖子,并尝试了许多不同的方法来解决我的问题后,我希望在您的帮助下找到解决方案
我想从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/->添加或删除成员标签,解释有可能更新/删除,但没有用户在我读到的每一篇文章都成功
1条答案
按热度按时间myzjeezk1#
Mailchimps API的工作原理,我使用此代码添加和删除标签:
使用Mailchimps官方PHP SDK
您必须遵循确切的数组结构,否则API将不会添加或删除标记。当发送不正确的数据结构时,API没有错误,这有点奇怪。它只会报告格式错误的JSON。