The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

403 Forbidden error trying to get a response

Highlighted
Visitor

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

        Try

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

      catch

       End try

 

am I missing setting a parameter?

4 REPLIES 4
Highlighted
Employee

Re: 403 Forbidden error trying to get a response

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

Re: 403 Forbidden error trying to get a response

Ryan,

 

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

 

-Darrell

Highlighted
Member

Re: 403 Forbidden error trying to get a response

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...

Highlighted
Employee

Re: 403 Forbidden error trying to get a response

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

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured