Getting members from a contact list via API


Getting members from a contact list via API

Hi there,


I am getting a list of members from a contact via API. When I save the xml file, all I see is Email and Name. There are some other fields i want to bring as well. How would I do that? 


Here is my code to get the xml file from ctct.

string uName = "user";
            string pWord = "password";
            string APIKey = "key";
            CredentialCache LoginCredentials = new CredentialCache();
            LoginCredentials.Add(new Uri("" + uName), "Basic", new NetworkCredential(APIKey + '%' + uName, pWord));
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("" +
                uName + "/lists/12/members");
            request.Credentials = LoginCredentials;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream str = response.GetResponseStream();
            byte[] inBuf = new byte[100000];

                int bytesToRead = Convert.ToInt32(inBuf.Length);
                int bytesRead = 0;
                while (bytesToRead > 0)
                    int n = str.Read(inBuf, bytesRead, bytesToRead);
                    if (n == 0)
                        break; // TODO: might not be correct. Was : Exit While
                    bytesRead += n;
                    bytesToRead -= n;
                FileStream fstr = new FileStream(@"\\fileserver\driver\Ctct\ContactMembers.xml", FileMode.OpenOrCreate, FileAccess.Write);
                fstr.Write(inBuf, 0, bytesRead);

            catch (Exception ex)
                throw new Exception("Exception: " + ex.Message);



Also, what happens if there are 300 members in the contact list? Will everything show up on the xml file? Not sure if it only takes 50 at a time?


Thanks in advance.




API requests for list members returns only the email address, name, and the URL for each contact as the value of the id attribute in the ContactListMemeber element of each Entry node.  The response will include a page of the first 50 contacts, and several link elements that include href attributes whose value is a URL that you use for an API request to retrieve the next 50, previous 50, or the current list.  


To retrieve details for a given contact, you need to use the URL for that contact in an call to the Contacts Collection API, which is appropriate if your activity is for up to 25 contacts, but you should use the Bulk Activities API to request additional details if your activity is for a large number of contacts (over 25).  The bulk Activities API returned formatted XML that includes information on whether your request was successful, and if so also gives you the URL where you can download the exported file (CSV or TXT format).  You'd need to include functions in your application to get and parse the information from the exported file.


I hope this information is a helpful start.  Let us know if you have any additional questions.



Mark Coleman
Support Engineer
Occasional Participant

Is the 50 contacts per page a new thing? I could swear it used to pull down all contacts.

In our REST API with a GET, 50 contacts per page is how we have always implemented this API.  Our Activities API allows you to queue up a bulk export activity, which is asyncronous CSV export, and then pull down a full list of all the contacts in a specific list in CSV format once that is complete.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page