addNewList() getting 404 error

Highlighted
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.
3 REPLIES 3
Highlighted
Moderator

I'm not familiar with the

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
Highlighted
Participant

Here is the code

hi david,

I am sorry that i didin't put the path for the sample code. here is the path
http://developer.constantcontact.com/node/35
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);
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(@"");

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
Moderator

RE: 404 Error

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=""http://www.w3.org/2005/Atom"">");
data.Append(@"<id>data:,</id>");
data.Append(@"<title/>");
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>");
Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured