Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need help adding a watcher to issue via Java

Jonathon Davis
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 12, 2018

Hey everyone,

Before I get a lmgtfy, I've done my fair share of research and are still shooting blanks. I'm looking to add a watcher to an issue through java using httpHeaders and httpEntity. I know I need to set the Content-type to application/json, but every time I add something other than the Authorization to the headers, I get a 400 null error. If I just have the authorization in the headers I get a 415 unsupported data type error. Code is below, please help and thanks in advance. 

 

Also, this code is simply a test to see how to get anything to go through. Once I figure out how to get something to go through it will be separated out into separated getHeaders() methods and so on. Currently just running through a main method covering all my bases manually. 

 

    String jiraU = "account";
String jiraP = "blah";
String encodedBasicAuthHeader = Base64.getEncoder().encodeToString((jiraU + ":" + jiraP).getBytes());
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Authorization", "Basic " + encodedBasicAuthHeader);
httpHeaders.add("Accept", "application/json");
httpHeaders.add("Content-Type", "application/json");
String email = "bob@builder.com";
String issue_ID = "TEST-1";
String json = "{\"name\":\"" + email + "\"}";
HttpEntity<String> httpEntity = new HttpEntity<String>(json, httpHeaders);
System.out.println(restTemplate.exchange(url + jira/rest/api/2/issue/issue_ID/watchers", HttpMethod.POST, httpEntity, String.class).getBody());

Thanks!

 

 

 

1 answer

0 votes
Jonathon Davis
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 16, 2018

Bump

Suggest an answer

Log in or Sign up to answer