403 Forbidden error trying to get a response

Occasional Participant

403 Forbidden error trying to get a response

'Using vb.net and just trying to get a response.  I get the correct results using the browser but not working using the code. My code is as follows:


Dim inStream As StreamReader
Dim webresponse As WebResponse
Dim request As WebRequest = WebRequest.Create("http://api.constantcontact.com/ws/customers/dbibby/contacts/")

request.Credentials = New NetworkCredential("api-key%{username}", "{password")
request.Method = WebRequestMethods.Http.Get


            webresponse = request.GetResponse()  ' Chokes here getting the response
            inStream = New StreamReader(webresponse.GetResponseStream())
            Dim results As String = inStream.ReadToEnd()


       End try


am I missing setting a parameter?


Hi DarrellB29,


I was looking through your code I would try changing your URI from, "http://api.constantcontact.com/ws/customers/dbibby/contacts/" to "http://api.constantcontact.com/ws/customers/dbibby/contacts".  

Let me know if the results change.

Thank You,

Ryan Davis
Quality Engineer
Occasional Participant



Thank you very much.  That solved the problem.  Way cool.



Occasional Participant

My Code is below for adding a contact:


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

        string sAPIKey = "****";

        Uri address = new Uri(sUri);
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
        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("ADD_CONTACTS", Encoding.UTF8));
        data.Append("&data=" + HttpUtility.UrlEncode(("Email Address,Email Type,Name"), Encoding.UTF8));
        data.Append(HttpUtility.UrlEncode((strEmail + ",HTML," + strName), Encoding.UTF8));
        data.Append("&lists=" + HttpUtility.UrlEncode(sListUri));


 Byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
        string st = string.Empty;
        request.ContentLength = byteData.Length;


        WebResponse webresponse = request.GetResponse();
        StreamReader reader = new StreamReader(webresponse.GetResponseStream());
        st = reader.ReadToEnd();



Bold line is giving me error... Please help me...

Hey Kathryne,


I would love to help you with your code however I wanted to verify what you are creating.  It looks like you are adding a contact one at a time using our Activities collection.  Doing so would be against our TOS and could cause potential issues with your account.  The Activities Collection is used when you are doing 20+ contacts at a time. 

If this form is to create a join my mailing list application it would need to be setup as it would create a contact one at a time using the contacts collection which you can read about here


Please let me know if you have any questions.

Ryan Davis
Quality Engineer
Developer Portal

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

Visit Page