DeviceExpert Java REST API

DeviceExpert Java REST API

Hey there,

I'm trying to connect to the DeviceExpert with the REST API inside of a java application.

My problem is that I'm getting an empty result returned and not a json object as it should be, but the connection responseCode is 200, so that should not be the problem.

Do I have to authenticate somehow before I can make the api call? Or is the generated api key enough?

Any help would be greatly appreciated.

The urlParameters look like for example:
  1. "API_KEY="+apiKey+"&ACTION=GET_ALL_DEVICE_TYPES"
And this is the function I use:
  1. private JSONObject sendPostRequest(String urlParameters, boolean debug) throws Exception
        {
            String request = "http://"+serverIp+":"+serverPort+"/api";
           
            URL url = new URL(request);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();  
           
            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setInstanceFollowRedirects(true);
           
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            connection.setRequestProperty("charset", "utf-8");
            connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
            connection.setUseCaches (false);

            DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
            wr.writeBytes(urlParameters);
            wr.flush();
            wr.close();
           
            if(debug)
            {
                int responseCode = connection.getResponseCode();
                CSCLog4Jv2.info("Sending request to URL : " + url);
                CSCLog4Jv2.info("Response Code : " + responseCode);
            }
                   
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();
               
            while ((inputLine = in.readLine()) != null)
                response.append(inputLine);
            in.close();
           
            connection.disconnect();
           
            CSCLog4Jv2.info("Response: "+response.toString());
           
            return null;
            //return new JSONObject(response.toString()).getJSONObject("response");
            //return new JSONObject(response.toString());
        }
























































                New to ADManager Plus?

                  New to ADSelfService Plus?