Get list size - PHP example

I thought I would throw up a php example on how to get the size of a list.

    //Sample using the CMBase.php wrapper
    //Relative path to CMBase.php. This example assumes the file is in the same folder
    //Your API Key. Go to to see where to find this and other required keys
    $api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    $client_id = null;
    $campaign_id = null;
    $list_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    $cm = new CampaignMonitor( $api_key, $client_id, $campaign_id, $list_id );
    //Optional statement to include debugging information in the result
    //$cm->debug_level = 1;
    //Subscribers added after the Date value specified will be returned. Must be in the format YYYY-MM-DD HH:MM:SS.
    $Date = '2009-05-01 01:01:00';
    //This is the actual call to the method
    $result = $cm->subscribersGetActive($Date);
    if($result['Result']['Code'] == 0)
        echo 'Success';
        echo 'Error : ' . $result['Result']['Message'];
    //check the size of the array
    $list_size = sizeof($result['anyType']['Subscriber']);
    echo '<p>Size of list: '.$list_size.'</p>';
    //Print out the debugging info

I hope that I've done this right - It works fine for me. It's really basic but handy when calculating the cost of a campaign.

Please let me know if there is anything wrong with this and I'll update it accordingly.


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