Hey guys
I am using exactly same java code for creating jira ticket using username:password and username:api_token.
I am able to create ticket using username:password (ofcourse encoded with base64) but when I am using the same code for api token , it is giving me 401 unauthorized - no body error with restTemplate.
Please suggest me the solution for this.
Thanks
Hi @Shubham ,
welcome to the Atlassian community!
Please could you share your REST API call (without user info) so that we can support you on that? How did u generate token for user?
Fabio
Hey @Fabio Racobaldo _Catworkx_
Yeah I have created token from my account profile>Personal Access token and using the same while authorization.
I am using something like this.. with proper url,username and api token.
public HttpHeaders createHeadersWithAuthentication()
{
String plainCreds = "myusername" + ":" + "api_token";
byte[] base64CredsBytes = Base64.getEncoder().encode(plainCreds.getBytes());
String base64Creds = new String(base64CredsBytes);
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add("Authorization", "Basic " + base64Creds);
return requestHeaders;
}
httpHeaders = createHeadersWithAuthentication();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
String url = "https://onejira.******.com/rest/api/2/issue";
HttpEntity<String> requestEntity = new HttpEntity<String>(jiraRequest.toString(), httpHeaders);
String jiraResponse = restTemplate.postForObject(url ,requestEntity, String.class);
When I am replacing
String plainCreds = "myusername" + ":" + "api_token";
with
String plainCreds = "myusername" + ":" + "mypassword";
It is working perfectly fine for me with the same lines of code.. even with postman i tried using token instead of password , both are working fine , only issue is with using token inside code.
Please help. Let m know if you require anything else from my side.
Thank You
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.