title: How to Access ServiceDesk Plus API through Java Application: Error Authorizing Technician Key
body: <p>I am attempting to use a Java application to call an http POST method in order to access the ServiceDesk Plus REST API as explained in their API documentation:<a href="http://www.manageengine.com/products/service-desk/help/adminguide/index.html" rel="nofollow">http://www.manageengine.com/products/service-desk/help/adminguide/index.html</a>.</p>
  
  <p>I followed the format for "Adding Request" in this documentation located at API/REST API/Request Operations/</p>
  
  <p>I am getting the following error message when running the java application: "<strong>API key received is not associated to any technician. Authentication failed.</strong>"</p>
  
  <p>I do not have admin rights to generate an API key, but I was given one by my boss. I am sure it is not expired or anything like that. For privacy reasons, I have not included the real key.</p>
  
  <p>This is the first time I have tried to use any API. I have basic textbook knowledge of java and object-oriented programming, but most of the code I used was copied. I am not at all familiar with the libraries and methods it uses, so I apologize if I am doing something dumb. Any help would be greatly appreciated :)</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.DataOutputStream;
  import java.io.InputStreamReader;
  import java.net.HttpURLConnection;
  import java.net.URL;
  
  import javax.net.ssl.HttpsURLConnection;
  
  public class HttpURLConnectionExample {
  
  private final String USER_AGENT = "Mozilla/5.0";
  
  public static void main(String[] args) throws Exception {
  
      HttpURLConnectionExample http = new HttpURLConnectionExample();
  
      System.out.println("\nTesting 1 - Send Http POST request");
      http.sendPost(); 
  
  }
  
  // HTTP POST request
  private void sendPost() throws Exception {
  
      String url = "https://sd.centerednetworks.com/sdpapi/request";
      URL obj = new URL(url);
      HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
  
      //add reuqest header
      con.setRequestMethod("POST");
      con.setRequestProperty("User-Agent", USER_AGENT);
      con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
  
      //define parameters
      String operation = "OPERATION_NAME=ADD_REQUEST";
      String techkey = "&amp;TECHNICIAN_KEY=XXXXXXXXXXXXXXXXXXX";
      String data = "&amp;INPUT_DATA=&lt;Operation&gt;&lt;Details&gt;&lt;parameter&gt;&lt;name&gt;requester&lt;/name&gt;               &lt;value&gt;Shawn Adams&lt;/value&gt;&lt;/parameter&gt;"
              + "&lt;parameter&gt;&lt;name&gt;subject&lt;/name&gt;&lt;value&gt;The subject of the request&lt;/value&gt;&lt;/parameter&gt;"
              + "&lt;parameter&gt;&lt;name&gt;description&lt;/name&gt;&lt;value&gt;The description of the request&lt;/value&gt;&lt;/parameter&gt;"
              + "&lt;parameter&gt;&lt;name&gt;callbackURL&lt;/name&gt;&lt;value&gt;http://localhost:8080/CustomReportHandler.do&lt;/value&gt;&lt;/parameter&gt;"
              + "&lt;parameter&gt;&lt;name&gt;requesttemplate&lt;/name&gt;&lt;value&gt;Unable to browse&lt;/value&gt;&lt;/parameter&gt;"
              + "&lt;parameter&gt;&lt;name&gt;priority&lt;/name&gt;&lt;value&gt;High&lt;/value&gt;&lt;/parameter&gt;"
              + "&lt;parameter&gt;&lt;name&gt;site&lt;/name&gt;&lt;value&gt;New York&lt;/value&gt;&lt;/parameter&gt;"
              + "&lt;parameter&gt;&lt;name&gt;group&lt;/name&gt;&lt;value&gt;Network&lt;/value&gt;&lt;/parameter&gt;"
              + "&lt;parameter&gt;&lt;name&gt;technician&lt;/name&gt;&lt;value&gt;Jeff Hein&lt;/value&gt;&lt;/parameter&gt;"
              + "&lt;parameter&gt;&lt;name&gt;level&lt;/name&gt;&lt;value&gt;Tier 3&lt;/value&gt;&lt;/parameter&gt;"
              + "&lt;parameter&gt;&lt;name&gt;status&lt;/name&gt;&lt;value&gt;Open&lt;/value&gt;&lt;/parameter&gt;"
              + "&lt;parameter&gt;&lt;name&gt;service&lt;/name&gt;&lt;value&gt;Email&lt;/value&gt;&lt;/parameter&gt;   &lt;/Details&gt;&lt;/Operation&gt;";
  
      //String urlParameters = operation + techkey + data;
      String urlParameters = operation + techkey + data;
  
      // Send post request
      con.setDoOutput(true);
      DataOutputStream wr = new DataOutputStream(con.getOutputStream());
      wr.writeBytes(urlParameters);
      wr.flush();
      wr.close();
  
      int responseCode = con.getResponseCode();
      System.out.println("\nSending 'POST' request to URL : " + url);
      System.out.println("Post parameters : " + urlParameters);
      System.out.println("Response Code : " + responseCode);
  
      BufferedReader in = new BufferedReader(
              new InputStreamReader(con.getInputStream()));
      String inputLine;
      StringBuffer response = new StringBuffer();
  
      while ((inputLine = in.readLine()) != null) {
          response.append(inputLine);
      }
      in.close();
  
      //print result
      System.out.println(response.toString());
  
    }
  }
  </code></pre>