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!
Bump
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.