0

I've written a java code to get survey list and then details of those surveys from my account. I am able to get the list of survey IDs but not the details of the survey, using the same API key.

Here's the url constructed:

https://api.surveymonkey.net/v2/surveys/get_survey_details/?api_key=---API-KEY--- --data-binary '{"survey_id":"---SURVEY-ID---"}'

Error:

Server returned HTTP response code: 400 for URL: https://api.surveymonkey.net/v2/surveys/get_survey_details/?api_key=---API-KEY--- --data-binary '{"survey_id":"---SURVEY-ID---"}'

The connection is setup as a post request:

private void resetConnection(String url){
    URL ourl;
    try {
        ourl = new URL(url.toString());
        conn = (HttpURLConnection) ourl.openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Authorization", "bearer " + SurveyMonkeyUrl.accessToken);
        conn.setRequestProperty("Content-Type", "application/json");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

If I try the URL in the browser it shows:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<h1>Developer Inactive</h1>

Note that the first query is executing fine with the provided same api key and access token.

EternallyCurious
  • 2,345
  • 7
  • 47
  • 78
  • What's the error text coming back with the 400 error? I suspect it's being sent as a GET rather than a POST. – Miles Cederman-Haysom Nov 05 '14 at 18:42
  • @MilesCederman-Haysom Question Updated! – EternallyCurious Nov 05 '14 at 18:55
  • The 400 error is not an error related to your API. The "Developer Inactive" message is a red herring. You will always get "Developer Inactive" when accessing API urls from a browser because you aren't posting a body. The example you posted is a curl syntax. If that error is being returned by your Java client, you're including "--data-binary..." in the URL which won't work; that's a curl parameter that tell curl to POST a specific data body in the request. – Tony Mayse Nov 05 '14 at 21:35
  • The 'developer inactive' is when your api key is not valid or not supplied. Check your java application supports sending query string parameters when POSTing to an endpoint. – Miles Cederman-Haysom Nov 05 '14 at 23:05
  • @MilesCederman-Haysom Not sure what specifically are you looking for? I've provided the full code for constructing the POST call above. The 'url' parameter is the url provided above. As I mentioned, the access key works fine for "get_survey_list" but not for "get_survey_details" – EternallyCurious Nov 06 '14 at 20:49
  • @EternallyCurious I misread your post, I didn't realize that was from putting the URL in the browser. What was the actual 400 error that came back from SurveyMonkey? – Miles Cederman-Haysom Nov 07 '14 at 23:05
  • possible duplicate of [How do I use SurveyMonkey's API console?](http://stackoverflow.com/questions/19061456/how-do-i-use-surveymonkeys-api-console) – Thomas Nov 08 '14 at 20:39

0 Answers0