Adding a Contact

I am attempting to add single contacts to a contactlist. I am using C# and have seen the sample code that was left. However, I have a few outstanding questions:
1. Confused about what contenttype to use.
2. What is the format for (contact) data string I need to compose?

Any help here would be greatly appreciated.

Answers



1. Use application/atom+xml as content type to send the data


2. Here is an example to format contact to send

<entry xmlns="http://www.w3.org/2005/Atom">
  <title type="text"> </title>
  <updated>2008-07-23T14:21:06.407Z</updated>
  <author></author>

  <id>data:,none</id>
  <summary type="text">Contact</summary>
  <content type="application/vnd.ctct+xml">
    <Contact xmlns="http://ws.constantcontact.com/ns/1.0/">
      <EmailAddress>test101@example.com</EmailAddress>

      <FirstName>First</FirstName>
      <LastName>Last</LastName>
      <OptInSource>ACTION_BY_CONTACT</OptInSource>
      <ContactLists>

        <ContactList id="http://api.constantcontact.com/ws/customers/joesflowers/lists/1" />
      </ContactLists>
    </Contact>
  </content>
</entry>

here is the link for more info http://developer.constantcontact.com/doc/contactsCollection
scroll down a little to look at Creating a new Contact section.

Adding contact issue

I am getting a 400 error returned. Is there something that anyone sees Im doing wrong? Thanks! FYI (C#)


My xml is not showing up with its data.appends below.....


string completeurl = surl + accountname + @"/contacts";            
            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";

            StringBuilder data = new StringBuilder();            
            data.Append("<entry xmlns='http://www.w3.org/2005/Atom'>");
            data.Append("<title type='text'></title>");
            data.Append("<updated>2008-07-23T14:21:06.407Z</updated>");       
            data.Append("<author></author>");
            data.Append("<id>data:,none</id>");
            data.Append("<summary type='text'>Contact</summary>");
            data.Append("<Contact xmlns='http://ws.constantcontact.com/ns/1.0/'>");
            data.Append("<EmailAddress>test101@example.com</EmailAddress>");
            data.Append("<FirstName>First</FirstName>");
            data.Append("<LastName>Last</LastName>");
            data.Append("<OptInSource>ACTION_BY_CONTACT</OptInSource>");
            data.Append("<ContactLists>");
            data.Append("<ContactList id='http://api.constantcontact.com/ws/customers/" + accountname +  "/lists/1'/>");
            data.Append("</ContactLists>");
            data.Append("</Contact>");
            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);
            }

Adding Contact - Need XML

I can't see what XML you are starting with (to append to). If you cannot post the XML which you are submitting, can you send it to our webservices support team?

n/a