【问题标题】:MailChimp API v3.0 - Can't update Tag of existing memberMailChimp API v3.0 - 无法更新现有成员的标签
【发布时间】:2020-05-26 10:23:13
【问题描述】:

我在尝试添加/更新现有用户的标签时遇到了一些问题。

当我更新现有成员信息时,它不会更新标签(使用方法“PATCH”)。它更新所有字段,但不更新标签。当我在列表中创建一个新成员(使用方法“POST”)时,它会创建标签。

我使用的代码是:

function add_suscriber($data)
    {
    //Data Format:
        //$data = array(
            //'apikey'        => $api_key,
            //'listid'        => $list_id,
            //'email_address' => $email,
            //'status'     => $suscripcion,
            //'tags'  => array($tags),
            //'merge_fields'  => array(
            //    'FNAME' => $nombre,       //nombre
            //    'LNAME' => $apellido,     //apellido
            //    'PAIS'  => $pais          //pais de residencia
            //    )
            //);
    $API_URL =   'https://' . substr($data['apikey'],strpos($data['apikey'],'-') + 1 ) . '.api.mailchimp.com/3.0/lists/' . $data['listid'] . '/members/' . md5(strtolower($data['email_address']));

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $API_URL);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic '.base64_encode( 'user:'.$data['apikey'] )));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data) ); 
    $result = curl_exec($ch);  
    curl_close($ch);

    $response = json_decode($result);                
    }

有了这个,当它是一个新用户时我没有问题;但如果用户已经存在(在任何受众中),所有内容都会更新,但标签不会更新。

提前感谢您的帮助!

【问题讨论】:

    标签: api curl tags mailchimp


    【解决方案1】:

    我也遇到过类似的问题,这很有效。

    这是我所做的:

    1. 使用获取现有成员的订阅者哈希

    $subscriberHash = $MailChimp->subscriberHash($contactEmail);

    1. 调用标签更新API

           $tagsSelected = ['ASH Tag 33','ASH Tag2 665'];
           foreach ($tagsSelected as $key=>$tag)
           {
      
               $tagArr['name']     = $tag;
               $tagArr['status']   = 'active'; //Put status = "active" for adding "inactive" for removing.
      
               $tagNameArrFnl[]    = $tagArr;
           }
           $parameters['tags'] = $tagNameArrFnl;
      
      
           $addTags  = $MailChimp->post('/lists/'.$listId.'/members/'.$subscriberHash .'/tags',$parameters);
      

    【讨论】:

      【解决方案2】:

      您无法通过补丁更新用户的标签。它仅在您添加新订阅者时按照文档中的说明工作。

      我与 Mailchimp 进行了交谈,并建议他们至少在文档中更清楚地说明这一点。

      我的解决方法是使用 /lists/{list_id}/segments/{segment_id}/members

      【讨论】:

        猜你喜欢
        • 2021-05-22
        • 2020-07-07
        • 2021-05-01
        • 2016-12-18
        • 2016-11-24
        • 2015-12-03
        • 2016-05-02
        • 2017-05-15
        • 2016-01-28
        相关资源
        最近更新 更多