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");
fields.add("key");
fields.add("assignee");
fields.add("summary");
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.