I am trying to call the REST API “rest/applinks/1.0/entitylink/”, which is a private API. I am able to use it from Fiddler, with an Authorization header, and it works frine. However, I would like to use it from my plugin’s Java code. This is my code.
String baseURL = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL);
String url = baseURL + “/” + restURL;
LoggerUtil.addDebug("Sending PUT request to Jira: " + restURL);HttpClient client = HttpClientBuilder.create().build(); HttpPut putRequest = new HttpPut(url); putRequest.addHeader("accept", "application/json"); StringEntity input = new StringEntity(jsonParamString, StandardCharsets.UTF_8); input.setContentType("application/json"); putRequest.setEntity(input); HttpResponse response = client.execute(putRequest); LoggerUtil.addDebug("Jira PUT Request code status: " + response.getStatusLine().getStatusCode()); if (response.getStatusLine().getStatusCode() != 200) { setCodeError(response.getStatusLine().getStatusCode()); LoggerUtil.addError("Jira PUT request status: " + response.getStatusLine().getStatusCode() + ", " + response.getStatusLine().getReasonPhrase()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; StringBuffer result = new StringBuffer(); while ((output = br.readLine()) != null) { result.append(output); }
However, I get a 401 Unauthorized error. I suppose it’s because I did not include the Authorization header, but I do not really know how to include it since I do not have the current user’s credentials. I might be able to fetch the current logged in user, but I am pretty sure I can’t fetch his password… How can I do a REST call using his user? Or maybe even do a REST call with no users, but with admin permissions.