Get contact does not contain lists in asp.net

I'm trying to get a contact with c# and the xml returned has the correct contact entry but does not include the lists of the contact.  I am using the code below:
 



        CredentialCache LoginCredentials = new CredentialCache();

        LoginCredentials.Add(new Uri(APIURI), "Basic", new NetworkCredential(APIKey + "%" + Username, Password));

        WebRequest Request = WebRequest.Create(ContactURI + "?email=" + email); // URI for the GET

        Request.Credentials = LoginCredentials;

        Request.Method = "GET";
 
        try
        {
            HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
            StreamReader Reader = new StreamReader(Response.GetResponseStream());
            string XMLResponse = Reader.ReadToEnd();
            Reader.Close();
            Response.Close();

            return XMLResponse;
        }
        catch (WebException e)
        {
            return "WebException: " + e.Status + " " + e.Message.ToString();
        }
        catch (Exception e)
        {
            return "Exception:" + e.Message.ToString();
        }
 
This returns 
 
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://api.constantcontact.com/ws/customers/<username>/contacts</id>
  <title type="text">Contacts for Customer: <username></title>
  <link href="http://api.constantcontact.com/ws/customers/<username>/contacts" />
  <link href="http://api.constantcontact.com/ws/customers/<username>/contacts" rel="self" />
  <author>
    <name><username></name>
  </author>
  <updated>2009-06-24T17:19:33.716Z</updated>
  <link href="/ws/customers/<username>/contacts" rel="first" />
  <link href="/ws/customers/<username>/contacts" rel="current" />
  <entry>
    <link href="/ws/customers/<username>/contacts/84499" rel="edit" />
    <id>http://api.constantcontact.com/ws/customers/<username>/contacts/84499</id>
    <title type="text">Contact: <requested-email></title>
    <updated>2009-06-24T17:19:33.725Z</updated>
    <author>
      <name>Constant Contact</name>
    </author>
    <content type="application/vnd.ctct+xml">
      <Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/<username>/contacts/84499">
        <Status>Active</Status>
        <EmailAddress><requested-email></EmailAddress>
        <EmailType>HTML</EmailType>
        <Name>brown, caleb</Name>
        <OptInTime>2009-06-24T16:49:05.905Z</OptInTime>
        <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
        <Confirmed>false</Confirmed>
        <InsertTime>2009-06-24T15:43:49.801Z</InsertTime>
      </Contact>
    </content>
  </entry>
</feed>
 
 Am I missing an extra step?

 
 
 

You are missing one

You are missing one additional step. This query returns the base contact entry.  To get the details for that contact you will also need to GET the full contact entry: https://api.constantcontact.com/ws/customers/<username>/contacts/84499.  
 
This should give you the information you are looking for. 

Dave B Support Engineer, Constant Contact

Thanks Dave B,  I feel like

Thanks Dave B, 
I feel like I'm almost there.
I've got the following code running, and I'm getting to the post now to update an existing user's email. And I believe the xml is set up correctly now.  
However, when I post the user's xml, it doesn't get any response and the user doesn't get added to my list.  Any thoughts when looking at the following code?
 
// get the configuration for constant contact as well as any params
    private readonly string APIKey = ConfigurationManager.AppSettings["ConstantContactKey"];
    private readonly string Password = ConfigurationManager.AppSettings["ConstantContactPass"];
    private readonly string Username = ConfigurationManager.AppSettings["ConstantContactUser"];
    private readonly string first = Utility.GetStringFromRequest("newsletter-first");
    private readonly string last = Utility.GetStringFromRequest("newsletter-last");
    private readonly string list = Utility.GetStringFromRequest("subscriber-type");

    private string APIURI = "https://api.constantcontact.com/ws/customers/{0}";
    private string ContactURI = "";

    private string email = Utility.GetStringFromRequest("newsletter-email").ToLower();
    private string ListURI = "http://api.constantcontact.com/ws/customers/{0}/lists/{1}";
    private XmlDocument doc;

    protected void Page_Load(object sender, EventArgs e)
    {
        email = Server.UrlEncode(email);

        APIURI = String.Format(APIURI, Username);
        ContactURI = APIURI + "/contacts";
        ListURI = String.Format(ListURI, Username, list);
        
        // get the user data
        string xml = Get();
        doc = new XmlDocument();
        doc.LoadXml(xml);

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
        nsmgr.AddNamespace("a", "http://www.w3.org/2005/Atom");

        // check for an entry
        XmlNode link = doc.SelectSingleNode("//a:entry/a:link", nsmgr);
        if (link == null)
        {
            Response.Write(Post());
        }
        else
        {
            // Get the list
            ContactURI = "https://api.constantcontact.com" + link.Attributes["href"].Value;
            xml = GetLists();

            doc = new XmlDocument();
            doc.LoadXml(xml);

            nsmgr = new XmlNamespaceManager(doc.NameTable);
            nsmgr.AddNamespace("cc", "http://ws.constantcontact.com/ns/1.0/");

            // append the xml returned by the get
            XmlNode lists = doc.SelectSingleNode("//cc:Contact/cc:ContactLists", nsmgr);
            XmlNode newList = doc.CreateElement("ContactList");
            XmlAttribute att = doc.CreateAttribute("id");
            att.Value = ListURI;
            newList.Attributes.Append(att);
            
            newList.InnerXml = "<link xmlns=\"http://www.w3.org/2005/Atom\" href=\"" + ListURI + "\" rel=\"self\"
><OptInSource>ACTION_BY_CUSTOMER</OptInSource><OptInTime>" + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd\\THH:mm:ss\\Z") +
</OptInTime>";

            lists.AppendChild(newList);
            
            // write the posted xml to a file for confirmation of xml format
            doc.PreserveWhitespace = true;
            XmlTextWriter wrtr = new XmlTextWriter(Server.MapPath("/test.xml"), System.Text.Encoding.Unicode);
            doc.WriteTo(wrtr);
            wrtr.Close();

            Response.Write(Put());
        }
    }

    private string Get()
    {
        CredentialCache LoginCredentials = new CredentialCache();
        LoginCredentials.Add(new Uri(APIURI), "Basic", new NetworkCredential(APIKey + "%" + Username, Password));
        WebRequest Request = WebRequest.Create(ContactURI + "?email=" + email); // URI for the GET

        Request.Credentials = LoginCredentials;
        Request.Method = "GET";
        Request.ContentType = "application/atom+xml";

        try
        {
            HttpWebResponse Response = (HttpWebResponse) Request.GetResponse();
            StreamReader Reader = new StreamReader(Response.GetResponseStream());
            string XMLResponse = Reader.ReadToEnd();

            Reader.Close();
            Response.Close();

            return XMLResponse;
        }
        catch (WebException e)
        {
            return "WebException: " + e.Status + " " + e.Message;
        }
        catch (Exception e)
        {
            return "Exception:" + e.Message;
        }
    }

    private string GetLists()
    {
        CredentialCache LoginCredentials = new CredentialCache();
        LoginCredentials.Add(new Uri(APIURI), "Basic", new NetworkCredential(APIKey + "%" + Username, Password));
        WebRequest Request = WebRequest.Create(ContactURI);

        Request.Credentials = LoginCredentials;
        Request.Method = "GET";
        Request.ContentType = "application/atom+xml";

        try
        {
            HttpWebResponse Response = (HttpWebResponse) Request.GetResponse();
            StreamReader Reader = new StreamReader(Response.GetResponseStream());
            string XMLResponse = Reader.ReadToEnd();

            Reader.Close();
            Response.Close();

            return XMLResponse;
        }
        catch (WebException e)
        {
            return "WebException: " + e.Status + " " + e.Message.ToString();
        }
        catch (Exception e)
        {
            return "Exception:" + e.Message;
        }
    }

    protected string Put()
    {
        CredentialCache LoginCredentials = new CredentialCache();
        LoginCredentials.Add(new Uri(APIURI), "Basic", new NetworkCredential(APIKey + "%" + Username, Password));
        HttpWebRequest Request = (HttpWebRequest) WebRequest.Create(ContactURI);

        Request.Method = "PUT";
        Request.ContentType = "application/atom+xml";
        Request.Credentials = LoginCredentials;

        string XMLData = doc.OuterXml;

        byte[] byteArray = Encoding.UTF8.GetBytes(XMLData);
        try
        {
            Request.ContentLength = byteArray.Length;
            string XMLResponse = "Bytes to send: " + byteArray.Length;
            Stream streamRequest = Request.GetRequestStream();

            streamRequest.Write(byteArray, 0, byteArray.Length);
            streamRequest.Close();

            HttpWebResponse Response = (HttpWebResponse) Request.GetResponse();
            StreamReader Reader = new StreamReader(Response.GetResponseStream());

            XMLResponse += Reader.ReadToEnd();

            Reader.Close();
            Response.Close();

            return XMLResponse;
        }
        catch (WebException e)
        {
            return "WebException: " + e.Status + " With response: " + e.Message;
        }
        catch (Exception e)
        {
            return "Exception:" + e.Message;
        }
    }
    private string Post()
   {
        CredentialCache LoginCredentials = new CredentialCache();
        LoginCredentials.Add(new Uri(APIURI), "Basic", new NetworkCredential(APIKey + "%" + Username, Password));
        HttpWebRequest Request = (HttpWebRequest) WebRequest.Create(ContactURI);
        Request.Method = "POST";
        Request.ContentType = "application/atom+xml";
        Request.Credentials = LoginCredentials;
        string xmldata = BuildXML();

        byte[] byteArray = Encoding.UTF8.GetBytes(xmldata);

        try
        {
            Request.ContentLength = byteArray.Length;
            string XMLResponse = "Bytes to send: " + byteArray.Length;

            Stream streamRequest = Request.GetRequestStream();

            streamRequest.Write(byteArray, 0, byteArray.Length);
            streamRequest.Close();
            HttpWebResponse response = (HttpWebResponse) Request.GetResponse();
            StreamReader Reader = new StreamReader(response.GetResponseStream());
            XMLResponse += response.StatusCode + " " + response.StatusDescription + " " + Reader.ReadToEnd();

            Reader.Close();
            response.Close();
            return "{success:1,message:'Thank you for subscribing.'}";
        }
        catch (WebException e)
        {
            Utility.Log(String.Format("CC Exception: first: {0}, last: {1}, email: {2}, list: {3}, webException: {4} with response: {5}", first, last, email, list, e.Status, e.Message));
            return "{success:0,message:'<br/>Your email has been saved and will be added at a later time.<br/>" + e.Message + "'}";
        }
        catch (Exception e)
        {
            Utility.Log(String.Format("CC Exception: first: {0}, last: {1}, email: {2}, list: {3}, error: {4}", first, last, email, list, e));
            return "{success:0,message:'<br/>Your email has been saved and will be added at a later time.<br/>" + e.Message + "'}";
        }
    }
    protected string BuildXML()
    {
        StringBuilder XMLData = new StringBuilder();
        XMLData.Append("<entry xmlns=\"http://www.w3.org/2005/Atom\">");
        XMLData.Append("<title type=\"text\"> </title>");
        XMLData.Append("<updated>" + DateTime.Now + "</updated>");
        XMLData.Append("<author>IFC</author>");
        XMLData.Append("<id>data:,none</id>");
        XMLData.Append("<summary type=\"text\">Contact</summary>");
        XMLData.Append("<content type=\"application/vnd.ctct+xml\">");
        XMLData.Append("<Contact xmlns=\"http://ws.constantcontact.com/ns/1.0/\">");
        XMLData.Append("<EmailAddress>" + email + "</EmailAddress>");
        XMLData.Append("<FirstName>" + first + "</FirstName>");
        XMLData.Append("<LastName>" + last + "</LastName>");
        XMLData.Append("<OptInSource>ACTION_BY_CONTACT</OptInSource>");
        XMLData.Append("<ContactLists>");
        XMLData.Append("<ContactList id=\"" + ListURI + "\" />");
        XMLData.Append("</ContactLists>");
        XMLData.Append("</Contact>");
        XMLData.Append("</content>");
        XMLData.Append("</entry>");
        return XMLData.ToString();
    }
 
Thanks for any help you can give.
 

Your code does look correct. 

Your code does look correct.  If you send a request to our API though, you will always get a response code of some kind.  It appears that there may be a problem with the URI you're posting to.  
 
Is it possible for you to post the URI you're sending to and the actual XML you're sending?  If you want to send it to our webservices support team if you don't want to post the information in the forums.

Dave B Support Engineer, Constant Contact