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("&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;
}