I am looking to use the ExactTarget API to get the subscriber counts of some of our lists.
I have been trying to work from the .NET sample provided here: https://code.exacttarget.com/question/how-can-you-check-subscriber-count-list-using-soap-api-without-exporting-subscribers
The code I have right now is at the bottom of this post.
What happens when I run it is: it takes an awfully long time (over 5-10 min) to get past the line:
"status = framework.Retrieve(rr, out requestID, out Results);"
And when it does finally finish that Retrieve, it claims there are 0 subscribers on the listId provided (by returning a Results object of length 0), when I have verified that there are actually many. So, the function takes forever and returns a totalResults value of 0.
If anyone knows what might be causing this, I'd appreciate the help/advice. Thanks!!
private int RetrieveSubscriberCount(string ListUsername, string ListPassword, string listId)
{
try
{
//Retrieve Subscribers for list
SoapClient framework = new SoapClient();
framework.ClientCredentials.UserName.UserName = ListUsername;
framework.ClientCredentials.UserName.Password = ListPassword;
//Local variables
APIObject[] Results;
String requestID;
String status;
ListSubscriber listSub = new ListSubscriber();
int totalResults = 0;
// Instantiate the retrieve request
RetrieveRequest rr = new RetrieveRequest();
rr.ObjectType = "ListSubscriber";
// Setting up a simple listid filter
SimpleFilterPart sf = new SimpleFilterPart();
sf.SimpleOperator = SimpleOperators.equals;
sf.Property = "ListID";
sf.Value = new String[] { listId };
//Add Filter and properties
rr.Filter = sf;
rr.Properties = new string[] { "SubscriberKey", "Status" };
do
{
status = framework.Retrieve(rr, out requestID, out Results);
totalResults += Results.Length;
}
while (status.Equals("MoreDataAvailable"));//This means there are more than 2500 records
Console.WriteLine("Total Subscribers in List " + listId + ": " + totalResults);
return totalResults;
}
catch (Exception ex)
{
MessageBox.Show("Error in RetrieveSubscriberCount: " + ex.Message, "Error - RetrieveSubscriberCount", MessageBoxButton.OK);
return 0;
}
}
Attribution to: dallasWT
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/33481