Hi Jira,
I do not understand why the below Java snipplet does not work. The JQL is simple with just the project name, yet it returns no results.
String jqlQuery = "project = MYPROJECT"; //simple project search <project>
// The payload definition using the Jackson library
JsonNodeFactory jnf = JsonNodeFactory.instance;
ObjectNode payload = jnf.objectNode();
{
ArrayNode fields = payload.putArray("fields");
fields.add("id,key,assignee");
payload.put("jql", jqlQuery); //search for project
payload.put("maxResults", 50);
//payload.put("nextPageToken", null);
}
// Connect Jackson ObjectMapper to Unirest
Unirest.setObjectMapper(new ObjectMapper() {
private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper
= new com.fasterxml.jackson.databind.ObjectMapper();
public <T> T readValue(String value, Class<T> valueType) {
try {
return jacksonObjectMapper.readValue(value, valueType);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String writeValue(Object value) {
try {
return jacksonObjectMapper.writeValueAsString(value);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
});
// This code sample uses the 'Unirest' library:
// http://unirest.io/java.html
HttpResponse<JsonNode> response = Unirest.post("<jira url>/rest/api/3/search/jql")
.basicAuth("<email>", "<api token key>")
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.body(payload)
.asJson();
System.out.println("Query Results:");
System.out.println(response.getBody());
The query results is blank
Query Results:
{"isLast":true,"issues":[]}
Is it because the Java code is using an API token and it is a permissions issue? The same account that created api token is able to read and write to the project.
I tried the below url from a browser and it returns results:
https://<my jira url>/rest/api/3/search/jql?jql=project=MyPROJECT
{"issues":[{"id":"109982"},{"id":"106128"},{"id":"104399"}...What did I do wrong in the Java REST call? It returns http200 with no results.
SOLVED. I am using an old api_token key that I deleted earlier. The weird part is that Jira Cloud REST is not smart enough to give me an authentication error. It instead returns http 200 (successful), even though the api_password is no longer valid.
It should have returned http 401 (unauthorized) for any api keys that were previously deleted or expired. Jira DEVs should fix this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Winston_Dang
Welcome to the Atlassian community.
You could ask your Jira Admins to open a support case to report that issue to Atlassian Technical Support to ensure that the issue has been added to their backlog.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Winston_Dang and @Trudy Claspill
A 200 response with invalid credentials is actually the expected behaviour for that endpoint.
If you refer to the endpoint's documentation, you will see where it says "This operation can be accessed anonymously", so, since the request credentials were invalid, it defaulted back to its default behaviour of processing the request as an anonymous one, but that anonymous request had no permission to get any data, so an empty set was returned.
I know this behaviour is confusing and it catches a lot of people out the first time they encounter it.
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.