addNewList() getting 404 error

Regular Participant

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.

I'm not familiar with the addNewList function you're referring to. Do you have the code for that so we can take a look at it or the sample program which you found the code in?

A 404 error does mean that the URI you're posting to could not be found. This is probably a case of incorrect information being passed to your function.
Dave Berard
Senior Product Manager, Constant Contact
Regular Participant

hi david,

I am sorry that i didin't put the path for the sample code. here is the path
and the code given there is as follows
public string addNewList(string accountname, string listname)

string username = "asdf1234" + % + "uname";
string completeurl = surl + accountname + @"/lists"; // collection uri

Uri address = new Uri(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();

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;

Without the actual values you're using for the surl and other variables, or at least the actual value of completeurl, it will be hard to tell you the exact cause of your error. This code creates the URL correctly provided the correct information. If you want to email me this information rather than post it here, feel free to send it over to our webservices support team. While looking at your code I see what I think is an unrelated issue to the 404 error. Your XML you're creating is incomplete and will not work. You need to use the full XML string builder he referenced:

data.Append(@"<entry xmlns="""">");
data.Append(@"<content type=""application/vnd.ctct+xml"">");
data.Append(@"<ContactList xmlns="""">");
data.Append(@"<Name>" + listname + "</Name>");
Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page