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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog