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.


Sample JAVA Docs

Hi,

Can someone at CC upload sample JAVA Docs?

Thank you,

Diego

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 .

n/a

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

c# sample code

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

vb.net

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

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.

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("&data=" + HttpUtility.UrlEncode("Email Address,Email Type,First Name,Last Name\n",Encoding.UTF8)); // +  + HttpUtility.UrlEncode("\n", Encoding.UTF8));
            data.Append("&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;
        }

This is how to retrieve a list

        public string[] retrieveLists(string accountname, string xpathselect)
        {
            string username = "asdf1234" + % + "uname";
            string completeurl = surl + accountname + @"/lists";

            List al = new List();

            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

  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(@"");
            data.Append(@"data:,");
            data.Append(@"");
            data.Append(@"<author/>");
            data.Append(@"<updated>2008-06-30</updated>");
            data.Append(@"<content type=""application/vnd.ctct+xml"">");
            data.Append(@"<ContactList xmlns=""http://ws.constantcontact.com/ns/1.0/"">");
            data.Append(@"<OptInDefault>false</OptInDefault>");
            data.Append(@"<Name>" + listname + "</Name>");
            data.Append(@"<SortOrder>92</SortOrder>");
            data.Append(@"</ContactList>");
            data.Append(@"</content>");
            data.Append(@"</entry>");

 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;
</pre><p></code></p>
<p>****, email me at <a href="mailto:cbaugh@gmail.com">cbaugh@gmail.com</a> for a clean copy of this post..</p>
          </div>
  </div>

      <div class="links"><ul class="links"><li class="comment_forbidden first last"><span><a href="/user/login?destination=comment/reply/35%2523comment-form">Login</a> or <a href="/user/register?destination=comment/reply/35%2523comment-form">register</a> to post comments</span></li>
</ul></div>
  </div>
<a id="comment-54"></a>
<div class="comment comment-published odd">

  <div class="clear-block">
      <span class="submitted">Wed, 10/01/2008 - 13:37 — tmignosa</span>
  
  
  
    <h3><a href="/node/35#comment-54" class="active">VB.NET Sample Code...see this external posting</a></h3>

    <div class="content">
      <p>Interested in VB.Net?  One user posted an example (Thanks!) here:<br />
<a href="http://www.codescene.com/2008/09/using-the-constant-contact-api.php" title="http://www.codescene.com/2008/09/using-the-constant-contact-api.php">http://www.codescene.com/2008/09/using-the-constant-contact-api.php</a></p>
            <div class="clear-block">
        <div>—</div>
        <p>Tom Mignosa, Product Manager, Constant Contact</p>
      </div>
          </div>
  </div>

      <div class="links"><ul class="links"><li class="comment_forbidden first last"><span><a href="/user/login?destination=comment/reply/35%2523comment-form">Login</a> or <a href="/user/register?destination=comment/reply/35%2523comment-form">register</a> to post comments</span></li>
</ul></div>
  </div>
<a id="comment-69"></a>
<div class="comment comment-published even">

  <div class="clear-block">
      <span class="submitted">Thu, 10/16/2008 - 16:45 — ToadicusRex</span>
  
  
  
    <h3><a href="/node/35#comment-69" class="active">Minor correction</a></h3>

    <div class="content">
      <p>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</p>
<p>//cc:ContactList/cc:Name </p>
<p>will work.</p>
          </div>
  </div>

      <div class="links"><ul class="links"><li class="comment_forbidden first last"><span><a href="/user/login?destination=comment/reply/35%2523comment-form">Login</a> or <a href="/user/register?destination=comment/reply/35%2523comment-form">register</a> to post comments</span></li>
</ul></div>
  </div>
<a id="comment-598"></a>
<div class="comment comment-published odd">

  <div class="clear-block">
      <span class="submitted">Thu, 04/30/2009 - 03:33 — pknair6</span>
  
  
  
    <h3><a href="/node/35#comment-598" class="active">how to retrieve contacts under a contactlist</a></h3>

    <div class="content">
      <p>please tell me how to retrieve contacts under a contact list</p>
          </div>
  </div>

      <div class="links"><ul class="links"><li class="comment_forbidden first last"><span><a href="/user/login?destination=comment/reply/35%2523comment-form">Login</a> or <a href="/user/register?destination=comment/reply/35%2523comment-form">register</a> to post comments</span></li>
</ul></div>
  </div>
<a id="comment-655"></a>
<div class="comment comment-published even">

  <div class="clear-block">
      <span class="submitted">Mon, 05/18/2009 - 04:55 — pknair6</span>
  
  
  
    <h3><a href="/node/35#comment-655" class="active">addNewList() getting 404 error</a></h3>

    <div class="content">
      <p>I think the addNewList(string accountname, string listname) is to add a new contact list to an account. Please correct me if i am wrong.<br />
But I couldn't find any place where we give the second parameter listname in the body of the function.</p>
<p>more over that I am getting 404 error when i run this programme.<br />
please help.</p>
          </div>
  </div>

      <div class="links"><ul class="links"><li class="comment_forbidden first last"><span><a href="/user/login?destination=comment/reply/35%2523comment-form">Login</a> or <a href="/user/register?destination=comment/reply/35%2523comment-form">register</a> to post comments</span></li>
</ul></div>
  </div>
<a id="comment-839"></a>
<div class="comment comment-published odd">

  <div class="clear-block">
      <span class="submitted">Mon, 06/22/2009 - 18:31 — csuh</span>
  
  
  
    <h3><a href="/node/35#comment-839" class="active">Please note that the above</a></h3>

    <div class="content">
      <p>Please note that the above example adds only one contact using Activities resource, but the Activities resource is only recommended for adding more than 25 contacts.  Please refer the <a href="http://developer.constantcontact.com/doc/activities">documentation on the Activities resource</a> to see how you can add more contacts to the example code above.<br />
To add one contact, please use the <a href="http://developer.constantcontact.com/doc/contactsCollection">Contacts resource</a>.</p>
            <div class="clear-block">
        <div>—</div>
        <p>Chang Suh<br />
Product Manager, Constant Contact</p>
      </div>
          </div>
  </div>

      <div class="links"><ul class="links"><li class="comment_forbidden first last"><span><a href="/user/login?destination=comment/reply/35%2523comment-form">Login</a> or <a href="/user/register?destination=comment/reply/35%2523comment-form">register</a> to post comments</span></li>
</ul></div>
  </div>
</div>          </div>
                    <div id="footer"><a href="http://www.constantcontact.com">Constant Contact Home Page</a>
<b>|</b> 
<a href="http://developer.constantcontact.com">Developer Web Site Home Page</a></div>
      </div></div></div></div> <!-- /.left-corner, /.right-corner, /#squeeze, /#center -->

              <div id="sidebar-right" class="sidebar">
          <div class="block block-theme"><form action="/node/35"  accept-charset="UTF-8" method="post" id="search-theme-form">
<div><div id="search" class="container-inline">
  <div class="form-item" id="edit-search-theme-form-1-wrapper">
 <label for="edit-search-theme-form-1">Search this site: </label>
 <input type="text" maxlength="128" name="search_theme_form" id="edit-search-theme-form-1" size="15" value="" title="Enter the terms you wish to search for." class="form-text" />
</div>
<input type="submit" name="op" id="edit-submit-1" value="Search"  class="form-submit" />
<input type="hidden" name="form_build_id" id="form-73e922e5a830715f7a6eda90b5a438f9" value="form-73e922e5a830715f7a6eda90b5a438f9"  />
<input type="hidden" name="form_id" id="edit-search-theme-form" value="search_theme_form"  />
</div>

</div></form>
</div>          <div id="block-user-0" class="clear-block block block-user">

  <h2>Forum Login</h2>

  <div class="content"><form action="/node/35?destination=node%2F35"  accept-charset="UTF-8" method="post" id="user-login-form">
<div><div class="form-item" id="edit-name-wrapper">
 <label for="edit-name">Username: <span class="form-required" title="This field is required.">*</span></label>
 <input type="text" maxlength="60" name="name" id="edit-name" size="15" value="" class="form-text required" />
</div>
<div class="form-item" id="edit-pass-wrapper">
 <label for="edit-pass">Password: <span class="form-required" title="This field is required.">*</span></label>
 <input type="password" name="pass" id="edit-pass"  maxlength="60"  size="15"  class="form-text required" />
</div>
<input type="submit" name="op" id="edit-submit" value="Log in"  class="form-submit" />
<div class="item-list"><ul><li class="first"><a href="/user/register" title="Create a new user account.">Create new account</a></li>
<li class="last"><a href="/user/password" title="Request new password via e-mail.">Request new password</a></li>
</ul></div><input type="hidden" name="form_build_id" id="form-e370c1f14e617b0dd8a4a0f911afcc94" value="form-e370c1f14e617b0dd8a4a0f911afcc94"  />
<input type="hidden" name="form_id" id="edit-user-login-block" value="user_login_block"  />

</div></form>
</div>
</div>
<div id="block-user-1" class="clear-block block block-user">

  <h2>Navigation</h2>

  <div class="content"><ul class="menu"><li class="leaf last"><a href="/tracker">Recent posts</a></li>
</ul></div>
</div>
<div id="block-forum-0" class="clear-block block block-forum">

  <h2>Active forum topics</h2>

  <div class="content"><div class="item-list"><ul><li class="first"><a href="/node/799" title="1 comment">Controlling what lists users see when they are un-subscribing</a></li>
<li><a href="/node/800" title="1 comment">Customization of the "Update your profile" and "Thanks you for joining our Mailing List" emails</a></li>
<li><a href="/node/795" title="3 comments">'could not find valid list with the name...' urgent assistance please.</a></li>
<li><a href="/node/801" title="1 comment">Adding "new" contact</a></li>
<li class="last"><a href="/node/754" title="4 comments">Custom field length limit is not documented.</a></li>
</ul></div><div class="more-link"><a href="/forum" title="Read the latest forum topics.">more</a></div></div>
</div>
<div id="block-comment-0" class="clear-block block block-comment">

  <h2>Recent comments</h2>

  <div class="content"><div class="item-list"><ul><li class="first"><a href="/node/799#comment-1528">Controlling List Visability</a><br />1 hour 49 min ago</li>
<li><a href="/node/800#comment-1527">Regarding modifying the</a><br />1 day 17 hours ago</li>
<li><a href="/node/795#comment-1526">Very sorry, here is the</a><br />1 day 18 hours ago</li>
<li><a href="/node/795#comment-1525">sorry... Which post? </a><br />1 day 19 hours ago</li>
<li><a href="/node/801#comment-1524">Yes, deleting a contact in</a><br />1 day 20 hours ago</li>
<li><a href="/node/754#comment-1523">Gary,
 
If you are working</a><br />1 day 22 hours ago</li>
<li><a href="/node/798#comment-1522">Unfortunately we do not have</a><br />1 day 22 hours ago</li>
<li><a href="/node/796#comment-1521">It should be noted we do not</a><br />1 day 22 hours ago</li>
<li><a href="/node/795#comment-1520">In June of this year we did</a><br />1 day 22 hours ago</li>
<li class="last"><a href="/node/793#comment-1519">Hi Moiz,
 
Are you adding</a><br />1 day 22 hours ago</li>
</ul></div></div>
</div>
        </div>
      
    </div> <!-- /container -->
  </div>
<!-- /layout -->

  <script type="text/javascript" src="/modules/google_analytics/googleanalytics.js?p"></script>
<script type="text/javascript">var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));</script>
<script type="text/javascript">try{var pageTracker = _gat._getTracker("UA-10082122-1");pageTracker._trackPageview();} catch(err) {}</script>
  </body>
</html>