I’m trying to fetch all Jira issues that were either created or updated today. Right now I can only grab a single issue by its key using my Apex code. I need help expanding this to get multiple issues based on their creation or update date.
Here’s what I’ve got so far:
public class JiraIssueRetriever {
public static void fetchIssueDetails(String issueId) {
Http h = new Http();
HttpRequest req = new HttpRequest();
String auth = 'Basic ' + EncodingUtil.base64Encode(Blob.valueOf('user:pass'));
req.setHeader('Authorization', auth);
req.setHeader('Content-Type', 'application/json');
req.setEndpoint('https://jira.mycompany.com/rest/api/2/issue/' + issueId);
req.setMethod('GET');
HttpResponse res = h.send(req);
}
}
How can I modify this to get all issues from today? Any help would be great!
I’ve dealt with a similar situation before, and I can share what worked for me.
Instead of fetching a single issue, you’ll need to use Jira’s search API. Modify your endpoint to ‘/rest/api/2/search’ and change your HTTP method to POST. Include a JQL query in the request body to filter your issues; for instance, you can use ‘created >= startOfDay() OR updated >= startOfDay()’ to get today’s issues.
Make sure to parse the JSON response to handle multiple issues and implement pagination if necessary, since Jira limits results by default. This approach should get you on the right track.
hey mike, i had a similar problem. try using the search API instead. change ur endpoint to ‘/rest/api/2/search’ and use POST. add a JQL query in the body like this:
‘project = YourProject AND (created >= -24h OR updated >= -24h)’
dont forget to parse the response for multiple issues. good luck!
Based on your current code, you can modify it to fetch multiple issues using Jira’s search API. Change your endpoint to ‘/rest/api/2/search’ and use a POST request. In the request body, include a JQL query like this:
This will fetch issues created or updated in the last 24 hours. You’ll need to parse the JSON response to extract multiple issue details. Consider implementing pagination if you expect more than 100 results. Remember to adjust the project name and tweak the JQL as needed for your specific use case.