I have created an API token in jira and with that token i can do a GET request like this:
curl https://<useremail>:zfO8D8QTrn6M4567cVChF46F@<mycompany>.atlassian.net/rest/agile/1.0/board/13/sprint?state=active
When in Java i send this request:
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("https://<useremail>:zfO8D8QTrn6M4567cVChF46F@<mycompany>.atlassian.net/rest/agile/1.0/board/13/sprint?state=active");
CloseableHttpResponse response1 = httpclient.execute(httpGet);
I get a 401
The httpClient is from apache:
'org.apache.httpcomponents:httpclient:4.5.7'
How can i authenticate with HttpClient ??
Allready tried UsernamePasswordCredentials.
I'm surprised that your curl with just the URL is able to return anything useful. Even when using curl, I would expect you to have to pass specific headers in your request in order to get back useful data. Please see our the Jira Software REST API for that endpoint GET /rest/agile/1.0/board/{boardId}/sprint.
In those documents, there are specific examples of how to make such requests using curl, php, python, and even Java.
The format for Java has this details:
// This code sample uses the 'Unirest' library:
// http://unirest.io/java.html
HttpResponse<JsonNode> response = Unirest.get("https://your-domain.atlassian.net/rest/agile/1.0/board/{boardId}/sprint")
.basicAuth("email@example.com", "<api_token>")
.header("Accept", "application/json")
.asJson();
System.out.println(response.getBody());
You aren't required to use the unirest library like our example, but I expect this to work.
I also found another resource that might be helpful. It appears to explain some more detailed steps for using the apache httpclient to make rest calls: RESTful Java client with Apache HttpClient
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.