I’m working on a project where I need to fetch all Jira tickets that were both created and modified today. Right now my code only works when I provide a specific ticket key, but I want to query multiple tickets based on date criteria.
I can successfully retrieve individual tickets by passing the ticket key to my API call, but I’m stuck on how to modify my query to get a list of today’s tickets instead of just one.
Here’s my current implementation:
public with sharing class TicketRetriever {
public static void fetchTicketData(String ticketId) {
HttpRequest request = new HttpRequest();
HttpResponse response = new HttpResponse();
Http httpClient = new Http();
String user = 'admin';
String pass = 'admin';
Blob authBlob = Blob.valueOf(user+':'+pass);
String basicAuth = 'Basic ' + EncodingUtil.base64Encode(authBlob);
request.setHeader('Authorization', basicAuth);
request.setHeader('Content-Type','application/json');
String apiUrl = 'https://mycompany.atlassian.net/rest/api/2/issue/'+ticketId;
request.setMethod('GET');
request.setEndpoint(apiUrl);
response = httpClient.send(request);
}
}
How can I modify this to get all tickets from today instead of just one specific ticket?
You’re targeting individual tickets but need batch retrieval. Switch from the issue endpoint to the search endpoint with JQL syntax.
Replace your endpoint:
String today = DateTime.now().format('yyyy-MM-dd');
String apiUrl = 'https://mycompany.atlassian.net/rest/api/2/search?jql=created >= "' + today + '" AND updated >= "' + today + '"';
I’m using AND instead of OR - this grabs tickets that meet both criteria like you wanted. The response contains a results object with an issues array instead of direct ticket data.
Watch out for the maxResults parameter since it defaults to 50 tickets. Also, Jira timestamps include time zones, so your query might miss tickets depending on server config. Test with a broader date range first to make sure the format works with your Jira instance.
Yeah, use the /search endpoint but heads up - timezone issues will bite you with those date strings. Skip the hardcoded dates and go with startOfDay() and endOfDay() functions instead. Your Jira and Salesforce instances are probably in different timezones, so you’ll miss tickets otherwise.
You’re hitting the wrong endpoint - that’s for single issues. Switch to the search endpoint with JQL for date filtering.
Use this instead:
String apiUrl = 'https://mycompany.atlassian.net/rest/api/2/search?jql=created >= startOfDay() AND updated >= startOfDay()';
This grabs tickets created or modified today. The response structure changes too - you’ll get a JSON object with an “issues” array, not a single ticket.
Honestly though, these integrations get messy quick. I’ve built Salesforce-Jira connections before and you’ll hit pagination, error handling, rate limits, auth token refreshes - it adds up.
I ended up using Latenode for this exact thing. It’s got native Jira and Salesforce connectors that handle all the API stuff automatically. Just drag the Jira search node, set your date filters visually, and connect whatever you need.
No hardcoded endpoints, no manual JSON parsing, no auth headaches. Easy to add filters or connect other systems without touching code.
Check it out: https://latenode.com
You’re hitting the single issue endpoint when you should be using the search API. Switch to JQL queries for date filtering:
String apiUrl = 'https://mycompany.atlassian.net/rest/api/2/search?jql=created >= "' + DateTime.now().format('yyyy-MM-dd') + '" OR updated >= "' + DateTime.now().format('yyyy-MM-dd') + '"';
This grabs tickets created OR updated today. Just know the response structure changes - you’ll get a JSON object with an “issues” array instead of a single ticket.
Heads up on a few gotchas: Jira’s date formats vary by instance. Some need the startOfDay() function, others want explicit date strings. Also watch for timezone mismatches between Salesforce and Jira.
Don’t forget pagination - the search endpoint caps at 50 results by default. Add maxResults and startAt parameters if you’re expecting more tickets.