Retrieving the entire Do Not Mail list

Regular Participant

Retrieving the entire Do Not Mail list

When I attempt retrieval of the Do Not Mail list (using API),  I only seem to be getting back the top 50 records from the actual web service at any given time. I cannot find any help on switches or recommended methods to obtain the entire list. What is the course of action I should take to get the entire Do Not Mail list programmatically?



Like all lists, the do-not-mail list will return a paginated response of up to 50 contacts per page. If there are more than 50 contacts existing in that list, we will return back a <link> node with the rel attribute "next". Access this link will take you to the next page of up to 50 contacts. Example:


 <link href="/ws/customers/{username}/lists/removed/members?next=glprxt9a-358boo" rel="next"></link>
  <link href="/ws/customers/{username}/lists/removed/members" rel="first"></link>
  <link href="/ws/customers/{username}/lists/removed/members" rel="current"></link>


I hope this clears things up. Please let us know if you have any other questions or concerns regarding this.

David J

So, if I needed to construct one list of all the contacts in the entire Do Not Mail list completely programmatically, are you telling me that there really isn't a straightforward way to do this?

If you're looking to get all list members in 1 shot, you have the option of creating an application/x-www-form-urlencoded or multipart/form-data Bulk Export Contacts Activity specifying the list id as "{username}/lists/do-not-mail". This would create a pending activity that once complete, would provide the URL of either an xls or txt file (depending on what you specified) containing your requested data.


If you would prefer to continue using the contacts collection to query for do-not-mail list members, we do have a number of code samples that could be used to loop through the list members as long as a next link is present.


I hope this helps. Please let us know if you have any other questions or concerns. Thanks.

David J

The reason I ask is because we have a timed service that needs to poll the Do Not Mail list in its entirety for changes on a periodic basis. If what you are saying is true, there really is no way to accomplish this programmatically without significant rewrites to the service as it sits today (currently uses the contacts collection). Do you have examples of how to go down the Bulk Export Contacts Activity route programmatically?

I can probably provide a bulk export contacts example in a pretty short amount of time. What language are you using?

David J

The service itself is written in C#. Thank you for any help you could be with this. This has certainly been a monumentally frustrating process to try to nail down.

I believe that the code below will do this for you. This is utilizing the C# Library which you can download from our Code Samples page.


AuthenticationData authdata = new AuthenticationData();
authdata.Username = "USERNAME";
authdata.Password = "PASSWORD";
authdata.ApiKey = "APIKEY";

String nextLink;
List<Contact> contacts = (List<Contact>) Utility.getListMembers("/ws/customers/"+authdata.Username+"/lists/do-not-mail", authdata, out nextLink);
while(nextLink != ""){
      List<Contact> nextPageContacts = (List<Contact>)    Utility.getListMembers(""+nextLink, authdata, out nextLink);

David J

Developer Portal

View API documentation, code samples, get your API key.

Visit Page