Hey everyone,
I’m trying to grab JIRA timesheet info through their REST API. I’ve already figured out how to retrieve JIRA issues using a console app with a custom REST client class that sends a GET request and receives a JSON response. That part is working well.
Now, I’m having trouble finding the correct API endpoint to obtain timesheet data in JSON format. I’ve explored several options without success, so any guidance or pointers on the proper endpoint would be greatly appreciated.
Thanks a bunch!
// Example code snippet
public class CustomJiraClient
{
private readonly HttpClient _client;
public CustomJiraClient(string baseUrl)
{
_client = new HttpClient { BaseAddress = new Uri(baseUrl) };
}
public async Task<string> FetchTimesheetDataAsync(string projectKey)
{
// TODO: Update with the correct endpoint
var response = await _client.GetAsync($"api/2/timesheet?project={projectKey}");
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}
}
I’d really appreciate any help on this. Thanks!
Thanks for sharing your code snippet, emmat83. While the ‘/rest/api/2/worklog’ endpoint mentioned earlier is a good starting point, it might not provide the full set of timesheet data you need. In my experience, a more reliable approach is to use the ‘/rest/api/2/search’ endpoint with a JQL query to first retrieve all relevant issues. After that, you can fetch the worklog details for each issue using the ‘/rest/api/2/issue/{issueId}/worklog’ endpoint. This method requires additional processing, but it offers greater flexibility when filtering and aggregating your timesheet data.
I’ve dealt with this exact issue recently. The JIRA REST API can be tricky for timesheet data. What worked for me was using a combination of endpoints. First, I’d query ‘/rest/api/2/search’ with a JQL to get relevant issues. Then, I’d hit ‘/rest/api/2/issue/{issueId}/worklog’ for each issue to grab detailed time logs.
Here’s a rough idea of how I structured it:
- Get issues using JQL
- For each issue, fetch its worklog
- Aggregate the data as needed
It’s not the most efficient, especially for large datasets, but it gives you granular control. You might need to implement pagination and handle rate limits. Also, don’t forget to use authentication headers in your requests.
One last tip: the Tempo API might be worth looking into if your JIRA instance uses that plugin. It offers more robust timesheet-specific endpoints.
hey emmat83, I’ve worked with JIRA API before. For timesheets, try the ‘/rest/api/2/worklog’ endpoint. it returns worklogs for issues, which is basically timesheet data. You’ll need to filter by project and date range. hope this helps!