Data not added to list

Regular Participant

Data not added to list

this is my code  the data is not added to list ,i am not getting why its not added to list


 


string Etype = "HTML";

         //   string Chr;

            string sUsername = "***";

            string sPassword = "****";

            string sUri = "https://api.constantcontact.com/ws/customers/" + sUsername + "/activities";

            string sListUri = "https://api.constantcontact.com/ws/customers/" + sUsername + "/lists/1";

            string sAPIKey = "********";

            Uri address = new Uri(sUri);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);

            // HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

            request.Credentials = new NetworkCredential((sAPIKey + "%" + sUsername), sPassword);

            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,Company Name" + Char(10)), Encoding.UTF8));

           // data.Append("&data=" + HttpUtility.UrlEncode(("Email Address,Email Type,First Name,Last Name,Company Name" + 10), Encoding.UTF8));

           // data.Append(HttpUtility.UrlEncode(( Email + ","+ Etype + "," +Fname + "," + Lname + "," + Org), Encoding.UTF8));





           // //data.Append("&data=" + HttpUtility.UrlEncode(("Email Address,Email Type,First Name,Last Name,Company Name" + '\n'), Encoding.UTF8));

           // //data.Append(HttpUtility.UrlEncode((txtEmail + ",HTML," + txtFirstName + "," + txtLastName + "," + txtOrganization), Encoding.UTF8));

           // data.Append("&lists=" + HttpUtility.UrlEncode(sListUri));





             //data.Append("activityType=" + HttpUtility.UrlEncode("ADD_CONTACTS", Encoding.UTF8));

   //data.Append("&data=" + HttpUtility.UrlEncode(("Email Address,Email Type,First Name,Last Name" + ""), Encoding.UTF8));

    //data.Append(HttpUtility.UrlEncode(("test@test.com" + ", HTML, " + "Test" + ", " + "Name"), Encoding.UTF8));

    // data.Append("&lists=" + HttpUtility.UrlEncode(sListUri));



    StringBuilder data = new StringBuilder();

    data.Append("activityType=" + HttpUtility.UrlEncode("ADD_CONTACTS", Encoding.UTF8));

    data.Append("&data=");

    data.Append(HttpUtility.UrlEncode("Email Address,", Encoding.UTF8));

    data.Append(HttpUtility.UrlEncode("Email Type,", Encoding.UTF8));

    data.Append(HttpUtility.UrlEncode("First Name,", Encoding.UTF8));

    data.Append(HttpUtility.UrlEncode("Last Name", Encoding.UTF8));

    data.Append(HttpUtility.UrlEncode("\n", Encoding.UTF8));

    data.Append(HttpUtility.UrlEncode("pramod@gmail.com ", Encoding.UTF8));

    data.Append(HttpUtility.UrlEncode("HTML, ", Encoding.UTF8));

    data.Append(HttpUtility.UrlEncode("pramod, ", Encoding.UTF8));

    data.Append(HttpUtility.UrlEncode("hu", Encoding.UTF8));

    data.Append("&lists=");

    data.Append(HttpUtility.UrlEncode(sListUri, Encoding.UTF8));

    byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());

    request.ContentLength = byteData.Length;



           // byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());

            string st = string.Empty;

           // request.ContentLength = byteData.Length;



            using (Stream postStream = request.GetRequestStream())

            {

            postStream.Write(byteData, 0, byteData.Length);

             }

  

         using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)

         {

             StreamReader reader = new StreamReader(response.GetResponseStream());

         }



        }



       

nvbnvbnvb

1 REPLY 1
Moderator

Please see this forum thread for the solution: http://developer.constantcontact.com/node/823

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page