So I am trying to retrieve output of JQL query using in Apex using API provided by Jira. However I am not able to format my body such that I receive the expected output in JSON file. here is my code
public class JiraRestClient {
private static final String JIRA_BASE_URL = 'https://sregmi48.atlassian.net';
private static final String JIRA_API_TOKEN = 'my_api_code';
public static HttpResponse getAllIssues(string jqlQuery) {
HttpRequest request = new HttpRequest();
request.setEndpoint(JIRA_BASE_URL + '/rest/api/3/search');
request.setMethod('POST'); // Use GET for searching issues by project key
request.setHeader('Authorization', 'Basic ' + EncodingUtil.base64Encode(Blob.valueOf('apiToken:' + JIRA_API_TOKEN)));
request.setHeader('Accept','application/json');
Map<String, Object> requestBodyMap = new Map<String, Object>{
'jql' => jqlQuery
};
String requestBodyJSON = JSON.serialize(requestBodyMap);
// String requestBody = '{"jql":{"project":{"key":"' + projectKey + '"}}}';
request.setBody(requestBodyJSON);
System.debug(requestBodyJSON);
return new Http().send(request);
}
}
Executing this code in the Anonymous window with
HttpResponse response = JiraRestClient.getAllIssues('project = "JIR"');
if (response.getStatusCode() == 415) {
String responseBody = response.getBody();
System.debug('Response Body: ' + responseBody);
List<String> responseHeaders = response.getHeaderKeys();
for (String key : responseHeaders) {
System.debug('Response Header ' + key );
}
} else {
String responseBody = response.getBody();
System.debug('Response Body: ' + responseBody);
}
However, I don't get any value in my JSON file.
And troubleshooting the issue shows that my response body format is not supported.

How do I solve this problem?