The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Getting Started with the API

Highlighted
Developer

Getting Started with the API

Welcome to the Getting Started with the API Forum!

This forum is intended to help new and returning users of the Constant Contact APIs apply the API. Appropriate forum topics include " Getting Started" topics as well as "How Do I...?" postings.




To review existing topics or to start a new thread in this Getting Started forum, go here.
For a list of forums, go here.


Tom M
Group Product Manager – Content Editing
Constant Contact
11 REPLIES 11
Highlighted

Sample JAVA Docs

Hi,

Can someone at CC upload sample JAVA Docs?

Thank you,

Diego
Highlighted
Developer

No Java Docs, but please see sample code here...

As this is a web services based API invoked via HTTP there is no direct access to the Constant Contact libraries and no JavaDoc. There is documented sample Java code showing some usage of the API here .
Tom M
Group Product Manager – Content Editing
Constant Contact
Highlighted
New Member

Are you looking for Javadoc for the Java sample application?

...or something else?

Javadoc for the sample app sounds like a good idea. We'll see what we can do.

Jim
Highlighted
Participant

c# sample code

Anybody attempting to call any of the CC api's from c#? Any success stories out there?
Highlighted
Occasional Advisor

vb.net

Have you had any success, anything to share with c#, we use vb.net but can easly convert.

Thank you,


Charles

Highlighted
Participant

c# sample code

It's not pretty, but here it is. Thanks to Kevin Mandeville @ CC or this would have never worked. And the only reason I'm posting this is BECAUSE he helped me. I personally think the docs and the API for CC need a tremendous amount of work. There are three main functions to know. Calling url, posting a named param list, posting an atom entry. Here are some examples. Note they aren't complete because of cut and paste but you should have everything you need. This is posting a named param set, ie, adding email address in. This is how to retrieve a list


        public string retrieveLists(string accountname, string xpathselect)

        {

            string username = "asdf1234" + % + "uname";

            string completeurl = surl + accountname + @"/lists";



            List<string></string> al = new List<string></string>();



            if (xpathselect == String.Empty)

            {

                xpathselect = "//at:title|//at:id";

            }



            Uri address = new Uri(completeurl);

            Debug.WriteLine(completeurl);



            HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

            request.Credentials = new NetworkCredential(username, pword);

            string st = String.Empty;



            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)

            {                



                // Get the response stream  

                StreamReader reader = new StreamReader(response.GetResponseStream());



                XmlTextReader xmlreader = new XmlTextReader(reader);



                XPathDocument doc = new XPathDocument(xmlreader);

                XPathNavigator pn = doc.CreateNavigator();



                XmlNamespaceManager ns = new XmlNamespaceManager(pn.NameTable);

                ns.AddNamespace("at", "http://www.w3.org/2005/Atom");

                ns.AddNamespace("cc", "http://ws.constantcontact.com/ns/1.0");



                XPathNodeIterator nodes = pn.Select(xpathselect,ns);



                bool bfirst = true;

                string stemp = String.Empty;



                while (nodes.MoveNext())                

                {

                   

                    // note. Don't attemp to use attributes. There aren't any....



                    XPathNavigator node = nodes.Current;



                    if (bfirst)

                    {

                        stemp = node.Value;

                        bfirst = false;

                    }

                    else

                    {

                        al.Add(stemp + "|" + node.Value);

                        stemp = String.Empty;

                        bfirst = true;

                    }

                }

               

            }



            return al.ToArray();

        }

       

    //This is how to post an atom entry. Notice the content type <code>



  public string addNewList(string accountname, string listname)

        {



            string username = "asdf1234" + % + "uname";

            string completeurl = surl + accountname + @"/lists"; // collection uri

           

            Uri address = new Uri(completeurl);

            Debug.WriteLine(completeurl);

            HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

            request.Credentials = new NetworkCredential(username, pword);

            request.Method = "POST";

            request.ContentType = @"application/atom+xml"; // key line



 StringBuilder data = new StringBuilder();

            data.Append(@"<entry xmlns="" www.w3.org=""></entry>");

            data.Append(@"<id></id>data:,");

            data.Append(@"");

            data.Append(@"<author></author>");

            data.Append(@"<updated></updated>2008-06-30");

            data.Append(@"<content application="" type=""></content>");

            data.Append(@"<contactlist xmlns="" ns="" ws.constantcontact.com=""></contactlist>");

            data.Append(@"<optindefault></optindefault>false");

            data.Append(@"<name></name>" + listname + "");

            data.Append(@"<sortorder></sortorder>92");

            data.Append(@"");

            data.Append(@"");

            data.Append(@"");



 byte byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());



            string st = String.Empty;



            // Set the content length in the request headers  

            request.ContentLength = byteData.Length;



            // Write data  

            using (Stream postStream = request.GetRequestStream())

            {

                postStream.Write(byteData, 0, byteData.Length);

            }



            // Get response  

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)

            {                

                // Get the response stream  

                StreamReader reader = new StreamReader(response.GetResponseStream());

                st = reader.ReadToEnd();

            }



            return st;

        }

****email me at cbaugh@gmail.com for a clean copy of this post..


string username = "asdf1234" + % + "uname";

string completeurl = surl + accountname + @"/activities";            



            Uri address = new Uri(completeurl);

            Debug.WriteLine(completeurl);

            HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

            request.Credentials = new NetworkCredential(username, pword);

            request.Method = "POST";

            request.ContentType = "application/x-www-form-urlencoded";



            StringBuilder data = new StringBuilder();

            data.Append("activityType=" + HttpUtility.UrlEncode("SV_ADD", Encoding.UTF8));

            data.Append("&amp;data=" + HttpUtility.UrlEncode("Email Address,Email Type,First Name,Last Name\n",Encoding.UTF8)); // +  + HttpUtility.UrlEncode("\n", Encoding.UTF8));

            data.Append("&amp;lists=" + HttpUtility.UrlEncode(listurl)); //  + @"lists/1"));

            byte byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());



            string st = String.Empty;



            // Set the content length in the request headers  

            request.ContentLength = byteData.Length;



            // Write data  

            using (Stream postStream = request.GetRequestStream())

            {

                postStream.Write(byteData, 0, byteData.Length);

            }



            // Get response  

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)

            {                

                // Get the response stream  

                StreamReader reader = new StreamReader(response.GetResponseStream());

                st = reader.ReadToEnd();

            }



            return st;

        }

 
Highlighted
Developer

VB.NET Sample Code...see this external posting

Interested in VB.Net? One user posted an example (Thanks!) here:
http://www.codescene.com/2008/09/using-the-constant-contact-api.php
Tom M
Group Product Manager – Content Editing
Constant Contact
Highlighted
Occasional Participant

Minor correction

When attempting to use the second namespace in the XmlNamespaceManager (i.e. "cc") please add an additional slash at the end of the url. Without it, it will fail, but with it

//cc:ContactList/cc:Name

will work.
Highlighted
Participant

how to retrieve contacts under a contactlist

please tell me how to retrieve contacts under a contact list
Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured