Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I pull the subscriber count from a MailChimp list with the API?
    primarykey
    data
    text
    <p>I'm trying to display the subscriber count from a MailChimp mailing list using their API, and I've got it partially working, except the code below is currently spitting out the subscriber count for all lists, rather than for one specific list. I've specified the list id in the line <strong>$listId ='XXX';</strong> but that doesn't seem to be working. Because I have five lists in total, the output from the PHP below shows this:</p> <p><strong>10 0 0 1 9</strong></p> <p>What do I need to do in my code below to get the subscriber count from a specific list id?</p> <pre><code>&lt;?php /** This Example shows how to pull the Members of a List using the MCAPI.php class and do some basic error checking. **/ require_once 'inc/MCAPI.class.php'; $apikey = 'XXX'; $listId = 'XXX'; $api = new MCAPI($apikey); $retval = $api-&gt;lists(); if ($api-&gt;errorCode){ echo "Unable to load lists()!"; echo "\n\tCode=".$api-&gt;errorCode; echo "\n\tMsg=".$api-&gt;errorMessage."\n"; } else { foreach ($retval['data'] as $list){ echo "\t ".$list['stats']['member_count']; } } ?&gt; </code></pre> <p>I just came across this function (see below) that let's me return a single list using a known list_id. The problem is, I'm not sure how to add the list_id in the function.</p> <p>I'm assuming I need to define it in this line? <strong>$params["filters"] = $filters;</strong></p> <p>The MailChimp <strong>lists()</strong> method documentation can be referred to here: <a href="http://apidocs.mailchimp.com/rtfm/lists.func.php" rel="nofollow">http://apidocs.mailchimp.com/rtfm/lists.func.php</a></p> <pre><code> function lists($filters=array ( ), $start=0, $limit=25) { $params = array(); $params["filters"] = $filters; $params["start"] = $start; $params["limit"] = $limit; return $this-&gt;callServer("lists", $params); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload