V1 XML (403) Forbidden Error - Activity Status

Highlighted
Occasional Participant

V1 XML (403) Forbidden Error - Activity Status

We are using the V1 API because we prefer to use xml over JSON. (we are currently using .Net 2.0)

 

Our API code is working successfully for Adding/Deleting contacts, and for pulling contacts via xml. However, when trying to create a contact export to CSV, we are unable to retrieve the Activity status or the link for the CSV file using the URI that is returned. We are getting an error without any detail: "(403) Forbidden"

 

The Access token and user name seem to be ok, because the other actions are working, and I'm passing the URI exactly as it is returned when I post.

 

Any ideas?

 

Here is my code:

Private Sub GetActivityStatus(ByVal activityUrl As String)

        Dim request As WebRequest = WebRequest.Create(activityUrl)
        request.PreAuthenticate = True

        request.Headers.Add("Authorization", "Bearer " + ConfigurationManager.AppSettings("AccessToken"))
        Try
            request.Method = "GET"

            Dim response As WebResponse = request.GetResponse()

            Dim respStream = response.GetResponseStream()
            Using xmlReader As New XmlTextReader(CType(respStream, System.IO.Stream))
                While Not xmlReader.EOF
                    tb_response.Text += xmlReader.ReadOuterXml
                End While
            End Using

        Catch ex As Exception
            tb_response.Text += ex.ToString
        End Try
    End Sub

 

6 REPLIES 6
Highlighted
Honored Contributor

Re: V1 XML (403) Forbidden Error - Activity Status

Hello,

 

After looking into this a bit and doing some testing, I think that the most likely reason is that the full URL in the returned POST body begins with http:// while the API requires HTTPS. The reasoning behind this has to do with the standards that were used when implementing the API, but it can be worked around relatively easily by doing the following:

Dim request As WebRequest = WebRequest.Create(activityUrl.Replace("http://","https://")

If you're still having trouble after this, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
Occasional Participant

Re: V1 XML (403) Forbidden Error - Activity Status

Hi,

 

I actually tried that earlier, based on other discussions on this forum, but that just returns a blank response.

 

Thanks

Highlighted
Honored Contributor

Re: V1 XML (403) Forbidden Error - Activity Status

Hello,

 

The next step would be to debug the code at this line:

Dim response As WebResponse = request.GetResponse()

You will want to check the request object and double-check the following:

  • Username in the URL is correct and matches the username associated with your access token
  • HTTPS is being properly used
  • Double-check the headers to make sure that the access token is being set properly.

 

If you'd like help with checking these, you could could send us a screenshot of the data above at webservices@constantcontact.com and we will be happy to look deeper!

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
Occasional Participant

Re: V1 XML (403) Forbidden Error - Activity Status

I sent the screenshot to that email address. Thanks!

Highlighted
Honored Contributor

Re: V1 XML (403) Forbidden Error - Activity Status

Hello,

 

I've been looking over the information that you sent and everything looks correct. I also tested the same request from my machine without error as well. The one thing I can see that might need to be changed is that you do not need to pre-authenticate when using OAuth, as you're manually including the header instead of providing credentials after a challenge from the server. If that does not work, you may want to debug the code to try and view the response, as out servers to return a response body on a 403 that provides a small amount of detail.

 

If you can get some details from that response, that would give us some information to move forward.

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
Occasional Participant

Re: V1 XML (403) Forbidden Error - Activity Status

Hi,

 

I finally got it to work. Changing to HTTPS worked to get rid of the 403 error. The reason it appeared to be returning a blank xml, was that I was missing the following line of code:

 

 xmlReader.Read()

Thanks for all your help!

Developer Portal

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

Visit Page

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured