Show (list) subsriber count on a website

Hi guys,

I would like to show the number of subscribers there are in one of my lists on a website. Just a simple output (e.g. "There are currently 1,530 subscribers")

I'm a front-end developer, so I'm struggling with the API! :(

I've downloaded the PHP API Wrappers, added my API key, list ID etc... and got it to output data, but I don't know how to turn that data into a simple output as mentioned above...

Here is what I can get it to output... There's only 1 subscriber in this particular list (a test), so I'm only interested in getting the first part (e.g. "TotalActiveSubscribers")...

I'm hoping there's a few lines of code I can use to display this data simply. Any help would be much appreciated.


terryt terryt, 4 years ago

Hi Andrew,

Without seeing your code, you're going to want something like this:

$activeSubscribers = $list_result_object->TotalActiveSubscribers;

Where $list_result_object is whatever object was returned from our API.  If you have any further questions, just attach a snippet of your code and we'll be sure to get you squared away!


Terry Tice
Campaign Monitor
roomfive, 4 years ago

Thanks Terry :)

I've got it to work (in part), but rather than just giving me a number it reads: "There are currently int(1) subscribers"

See working example

...Is there any way to clean this clean this up so I just get a number, like: "There are currently 1 subscribers"

Code now looks like:


require_once 'csrest_lists.php';

$wrap = new CS_REST_Lists('3bb11eee3a6112a6a9a32a0f8a0968dd', '178d97fedc74fd744e95711397535272');

$result = $wrap->get_stats();

echo "There are currently ";
if($result->was_successful()) {
    echo "<strong>";
    var_dump($activeSubscribers = $result->response->TotalActiveSubscribers);
    echo "</strong> subscribers";
} else {
    echo 'Failed with code '.$result->http_status_code."\n<br /><pre>";

terryt terryt, 4 years ago

Hi Andrew,

You won't want to do var_dump on that.  If you just do:

echo $result->response->TotalActiveSubscribers;

That should give you what you're looking for.  Again, let me know if you need anything else!


Terry Tice
Campaign Monitor
roomfive, 4 years ago

Amazing! Thanks Terry. Works perfectly! :)

Join 150,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free