Reputation: 1698
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?
Upvotes: 0
Views: 631
Reputation: 21
You got it Aaron... hopefully this helps others who run into the same issue: http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#read-get_lists_list_id_members_subscriber_hash
If you can't get to that URL, here's the summary:
use an HTTP GET
request to the URL /lists/{list_id}/members/{subscriber_hash}
with the subscriber_hash
being the MD5 hash of the lowercase version of the list member’s email address.
Upvotes: 0
Reputation: 1698
Just append the URL with the MD5 of email address in all lowercase. Too easy, I missed that in the MailChimp API docs.
Upvotes: 0