This is my first time using the MailChimp API, I've been looking at some examples and trying to figure out this on my own but I can't seem to be able to get what I need.
I only have one list on my account and I'm trying to run a contest where I choose one random winner from the list. So far I've managed to retrieve the total number of members on the list, and from that I have generated a random number to be used as the 'winner'. Now I need to find the member from the list located in that position from the list members array, but I'm not sure how to go about it.
This is what I have so far:
include "Mailchimp.php";
/* Load member count */
function mcg_mc_sub_count() {
$MailChimp = new MailChimp('*****');
$list = $MailChimp->call('lists/list');
$total_members .= $list[data][0][stats][member_count];
return number_format($total_members);
}
/* Generate random number */
function mcg_mc_random_number() {
$total_members = mcg_mc_sub_count();
$random_number = rand(1, $total_members);
return $random_number;
}
I think at this point I should be using $MailChimp->call('lists/member-info');
but since I only have a random position and not a member id/email, I'm not sure which parameters to use or how to go about it.
Any help is appreciated figuring this method out or through a different way, thanks!
I think your logic is correct. MailChimp does not provide an API for random member, but you can get list and create randon function in the array.
Example:
So, with the list, you can call the members and put in the array. Then you can use some function to get a random value in the array.
Refs: