I'm new both to Campaign Monitor as well as the API, but I've integrated the full subscribe/unsubscribe process into my site using the API (not using auto-generated forms or anything).
But what I now would like, is to get the *number* of active subscribes to a certain list, dynamically via the API. Is there any way to do this?
Script language is PHP by the way.
Thanks a lot for any advice!
Yes, you can do this using the Subscribers.GetActive method and using the count() function to count the number of active subscribers returned.
Hope that helps.
Thanks for your reply. I guess my PHP knowledge is limited after all.
So I'm calling GetActive and that returns an array with all the emailes etc.
If I use the standard coun()-function on it, I get the number 1 as a result. If I run count() in COUNT_RECURSIVE mode instead, I get 10225 as the subscriber count, which is way too many. I guess it counts each field (email, date, state). But then it should be enough to just divide that by 3? No, that doesn't work either. Still the wrong number.
What am I missing? Am I being really stupid here? :) I looked around for ways to extract only certain info from the array, but that didn't go too well.
Thanks a lot for your help here.
It would be great to get this in the List.GetDetail API call... it seems overkill to me to pull down details of every subscriber just to get a total count - on a large list this could be quite a lot of data to pull down over the wire?
$subscribers = $cm->subscribersGetActive( 0 , $listid );
$count = count( $subscribers['anyType']['Subscriber'] );
That should do the trick.
Make sure the $subscribers array has the same structure with one and several entries before counting according to this thread: http://www.campaignmonitor.com/forums/viewtopic.php?id=2765
I totally agree. If there is a votecount on this, add one for me ;)
A new List.GetStats API method will be available in our next release, which will return an object containing the following data for a list:
We decided to separate the statistics of a list from the "details" of a list by adding this new method rather than combining everything into the existing List.GetDetail method.
Since it's currently in development, are there any other list stats which people would find valuable?
It would be usefull to get also the amount of unsubscribes and bounces within this API call.
Another thing I can think of is to include the stats of last week, month, year to be able to compare them without having to save these data regularly into a database.
List.GetStats has recently been updated to include stats for active subscribers, unsubscribes, deleted and bounced subscribers, which allows you to easily get a current snapshot of stats for your list.
That's awesome! Will save us a quite a few lines of code in the future. Thanks for including our suggestions aswell!
Unfortunately I noticed that in some cases the call List.GetStats seems to deliver incorrect values. I have a list for example with 2 active subscribers but the call returns TotalActiveSubscribers = 1.
I was wondering if there was some error in our code that caused these wrong numbers but it seems to be already the API which delivers incorrect values. Could you please take a look and see if you can fix it?
Pete - joomailer
Could you contact support with the details of the client and list for which you're seeing this problem, as well as the the API key you're using? That will help us track down what the problem could be.
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