Get all subscribers

Hi all,

I'm wondering if anyone has a better way than I do to get all the subscribers across all lists/clients in an account? At the moment, I have code which gets the list of clients, gets the list of lists for each client, then gets the subscribers for each list. Some of this can be removed by maintaining static lists of clients or of lists but fundamentally the process remains the same.

Is there a better way? One which doesn't require so many calls via the API?



blad, 6 years ago

Hi Jeffery
Not sure it's the 'best' way to do it, but you can access a list directly if you know the keys. I've chosen to dump all the custom fields, you may want to be more specific about what you get. While the examples provided with the API are great, they can seem a bit advanced to just pick up and use.
It took me a while to work through how to do this, so happy to share it with others in the hope it speeds up your own learning curve!


PS. Can a CM person comment on doing this way ie. is it naughty/not robust, apart from the hard-coding of the list ids?

echo "CM Dump list of subscribers by direct access to list<br />";
require_once './csrest_lists.php';

$apikey = "xxxxxx";
$listId = "yyyyyy";

// Get subscriber information directly from a list
$myList = new CS_REST_Lists($listId, $apikey);
$subscribersObj = $myList->get_active_subscribers('2001-01-01 00:00:00.00');
$subscribers = $subscribersObj->response->Results;
$subNum = 0;
foreach ($subscribers as $s) {
    echo "SUBSCRIBER NUMBER : " . ++$subNum . "<br />";
    echo "Email: " . $s->EmailAddress . "<br />";
    echo "Name: " . $s->Name . "<br />";
    echo "Date: " . $s->Date . "<br />";
    echo "Subscriber State: " . $s->State . "<br />";
    foreach($s->CustomFields as $c) {
    echo $c->Key . " : " . $c->Value . "<br />";
echo "<br />DONE";
jamesd jamesd, 6 years ago

We provide a RESTful HTTP-based API, which obviously isn't suited to exporting massive amounts of data. "Getting all subscribers" for some customers would mean downloading millions and millions of subscriber records.

The key question is, do you need to do this on a regular basis? If you do need to get all subscribers on a regular basis, you may need to re-think why you need to and whether there's a better way of interacting with Campaign Monitor.

If it's not a regular process and it's more of a once-off export, exporting subscribers from within the Campaign Monitor application may be more suited to your needs.

trendap, 6 years ago

Thanks blad for the code!

For anyone using it, something to keep in mind with the get_active_subscribers() call is that it only exports the first 1000. So if your list is bigger, custom variables will need to be put in there for the next pages after the first 1000.

Looking into the source code right now for get_active_subscribers(), but I'll check out how to iterate through the pages:

* Gets all active subscribers added since the given date
     * @param string $added_since The date to start getting subscribers from
     * @param int $page_number The page number to get
     * @param int $page_size The number of records per page

See why 200,000 companies worldwide love Campaign Monitor.

From Australia to Zimbabwe, and everywhere in between, companies count on Campaign Monitor for email campaigns that boost the bottom line.

Get started for free