douzong2206 2015-09-11 14:29
浏览 46
已采纳

如何使用API​​ 3.0从MailChimp列表获取单个记录,通过电子邮件地址过滤

Flowing new subscribers from our CRM into MailChimp was easy, but what I need to do now is to get a single customer record based on only their email address and fetch their MailChimp ID from the MailChimp API.

The MailChimp API 3.0 documentation has limited examples of using filters for GET calls. I would think it would be possible to filter the results without retrieving the entire member list, which is what the script is doing now, but I just need that one customer record, not the entire list else I receive the entire JSON string of every member of the list, encode this massive string into an array then I need to iterate through the JSON array to find the record with the matching email address, which seems very inefficient to me. I MUST be missing something that's not easily found in the MailChimp API 3.0 docs, no?!

I am using the PHP library, but it doesn't matter, I really just need to know how to build the API call -- the proper URL (can I append with ?email_address=EMAIL_TO_FILTER tried it but didn't work) and the JSON array structure. I have a successful connection with the MailChimp API and built a mailChimpApiRequest() method like so:

function mailChimpApiRequest($method='POST', $url, $postFields = null){

    $ch  = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);

    $headerArr=array(   'Authorization: '  . $this->apikey);

    if($method!='POST' && !empty($method)) {
      //Not needed: $headerArr[] = 'X-HTTP-Method-Override: ' . $method;
    }

    curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $method );
    curl_setopt($ch, CURLOPT_HTTPHEADER,$headerArr );
    curl_setopt($ch, CURLOPT_POST, true);

    if ($postFields) {
        if ($method!=''){    $postFields['method']=$method;}

        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postFields));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    }

    $curl_response = curl_exec($ch);
    curl_close($ch);

    return $curl_response;
}

Can somebody help me figure out what $url and $postFields array to pass to this mailChimpApiRequest() method above?

  • 写回答

2条回答 默认 最新

  • dongzz4545 2015-09-11 15:53
    关注

    Just append the URL with the MD5 of email address in all lowercase. Too easy, I missed that in the MailChimp API docs.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分