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 .
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(@" ");
data.Append(@"2008-06-30 ");
data.Append(@"");
data.Append(@"");
data.Append(@"false ");
data.Append(@"" + listname + " ");
data.Append(@"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..
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 Mignosa, Product Manager, Constant Contact
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.
how to retrieve contacts under a contactlist
please tell me how to retrieve contacts under a contact list
addNewList() getting 404 error
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.
But I couldn't find any place where we give the second parameter listname in the body of the function.
more over that I am getting 404 error when i run this programme.
please help.
Please note that the above
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 documentation on the Activities resource to see how you can add more contacts to the example code above.
To add one contact, please use the Contacts resource.
Chang Suh
Product Manager, Constant Contact