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.
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
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!
I actually tried that earlier, based on other discussions on this forum, but that just returns a blank response.
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:
If you'd like help with checking these, you could could send us a screenshot of the data above at firstname.lastname@example.org and we will be happy to look deeper!
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.
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:
Thanks for all your help!
View API documentation, code samples, get your API key.Visit Page
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