0

I built a C# application about 8 months ago to pull SurveyMonkey responses and store them on our SQL Server. The application has run every day for over 6 months without any issue, but suddenly Friday morning I can't get any requests to go through. I'm not seeing anything on the developer site mentioning outages, so I've been examining my code for possible issues.

This is the first app I've ever written to create web requests, so it's possible I'm doing things badly.

Request, from Fiddler:

POST https://api.surveymonkey.net/v2/surveys/get_survey_list?api_key=<key hidden> HTTP/1.1
Authorization: bearer <token hidden>
Content-Type: application/json
Host: api.surveymonkey.net
Content-Length: 146
Expect: 100-continue
Connection: Keep-Alive

{
"page": 1,
"fields": ["title","analysis_url","preview_url","date_created","date_modified","language_id","question_count","num_responses"]
}

Response body, from Fiddler:

{"status":1,"errmsg":"Request header \"Authorization\" token not found"}

C# code:

private JObject SubmitPostRequest(string URIPath, string RequestBody)
{
    using (var webClient = new WebClient())
    {
        // Create URI for POST request to go to. URI varies depending on API method and includes API Key.
        Uri requestURI = new Uri(APIHost, URIPath + "?api_key=" + APIKey);

        // Have web client use NT credentials for proxy server
        webClient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;

        // Specify headers: access token in authorization header, content type
        webClient.Headers["Authorization"] = "bearer " + AccessToken;
        webClient.Headers["Content-Type"] = "application/json";

        // Create requestBody as byte[]
        byte[] requestBody = Encoding.Default.GetBytes(RequestBody);

        // Connect to the URI and send requestBody as a POST command.
        byte[] postResponse = webClient.UploadData(requestURI, "POST", requestBody);

        // Update LastConnect
        LastConnect = DateTime.Now;

        ++TransactionCounter;

        // Convert byte[] response to string, parse string and return as JObject.
        JObject jsonResponse = JObject.Parse(Encoding.Default.GetString(postResponse));

        // Evaluate "status" field of jsonResponse. Throw exception if response is not 0.
        dynamic dyn = jsonResponse;
        if (dyn.status != 0)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("HTTP Post request failed:");
            sb.Append("\tstatus: ").AppendLine(dyn.status.ToString());
            sb.Append("\terrmsg: ").AppendLine(dyn.errmsg.ToString());
            throw new WebException(sb.ToString());
        }

        return jsonResponse;
    }
}
Eric Harlan
  • 374
  • 2
  • 9
  • What error is your logging indicating? No point asking a question if you don't have that. Are you certain they haven't updated their API? When was the last time you made changes to your application? If you have made a change, what happens when you roll back to the previous version? Have you contacted Survey Monkey to see if they made any changes? – user1666620 Nov 17 '14 at 16:45
  • The error is "Authorization token not found" and it happens anytime a request is made. If they've made changes to the API, they have yet to post any updates to the developer site (https://developer.surveymonkey.com/). The application runs every day and last successfully ran early AM on Thursday, 11/14/2014. No changes to code have been made in months. I have no contacted Survey Monkey directly, as they request you post to StackOverflow before contacting them. – Eric Harlan Nov 17 '14 at 17:04
  • 1
    I can tell you that nothing appears to have changed on the SurveyMonkey side and no one else is having these errors. I suspect something has changed on your end that is stripping out the headers. Are you able to dump the header data that is being sent to SurveyMonkey? – Miles Cederman-Haysom Nov 17 '14 at 19:23
  • The post contains the web traffic that I know how to see (as seen by Fiddler, outside of Visual Studio). Is there some other way I can pull the header data that would be better? This is also just what's being seen on my machine, so if it's something like the corporate proxy causing problems, I have no idea how I'd be able to verify that. – Eric Harlan Nov 17 '14 at 19:29
  • I forgot to mention, the developer console is working fine. I'm not sure what to make of it all. – Eric Harlan Nov 17 '14 at 19:46
  • 2
    I suspect it may be something like your corporate proxy manipulating it. Unfortunately I don't have visibility on my side into what's being sent through. – Miles Cederman-Haysom Nov 17 '14 at 20:31
  • I would email the API support team, they should be able to help you out. – Miles Cederman-Haysom Nov 17 '14 at 20:34
  • Thanks for all the help. I'm going to try the existing codebase at home, outside the VPN. If it works, I'll get with IT and see what changed last week. – Eric Harlan Nov 17 '14 at 20:55

1 Answers1

0

It took awhile, but I managed to get in touch with someone in corporate IT who monitored the traffic to see what was going on. They implemented a fix to the proxy server and everything is finally working again.

Eric Harlan
  • 374
  • 2
  • 9