Calculate work logged by a specific user across multiple Jira Cloud issues
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Disclaimer
The below example of a Python code is provided on as-is basis. Further support may not be available. Use at your own discretion and always make sure you know what you are doing.Summary
If you want to calculate work time logged by a specific user across multiple Jira Cloud issues, there is no existing native way to achieve this using JQL or Dashboard Gadgets.
Usecase
Multiple users were contributing to a single project and you want to calculate total time a specified user logged across selected issues.Environment
This has been tested on Jira Cloud Premium.
Solution
You may use the code, published below to calculate time logged across multiple tickets by a specified user. Be sure to update it to your needs.
Prerequisites
Installed Python and PIP:
https://www.python.org/downloads/Installed requests module:
Run in Terminal: pip install requestsJira Cloud API token:
Manage API tokens for your Atlassian account.
Input:
- JQL - to filter issues, we want to calculate the work log time across.
- Login email - email address of the API Key owner
- API Key - of the user, who has access to all projects/issues, returned by the above JQL.
- Search email - the email of the user, we calculating the logged time for.
Output:
- Number of minutes logged by above specified user across issues, filtered out by the above mentioned JQL.
Example:
Input:
JQL_QUERY = 'worklogDate >= "2024-01-01" and worklogDate <="2024-06-30"'
LOGIN_USER_EMAIL = 'admin@domain.com'
API_TOKEN = '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'
SEARCH_USER_EMAIL = 'user@domain.com'
Output:
Time logged is 787m
Code
import requests
from requests.auth import HTTPBasicAuth
JQL_QUERY = 'worklogDate >= "2024-01-01" and worklogDate <="2024-06-30"'
LOGIN_USER_EMAIL = 'admin@domain.com' # email of the API token owner
API_TOKEN = 'paste_token_here'
SEARCH_USER_EMAIL = 'user@domain.com' # email of the user we are counting time of
JIRA_URL = 'https://your-domain.atlassian.net'
SEARCH_URL = f'{JIRA_URL}/rest/api/3/search'
WORKLOG_URL = f'{JIRA_URL}/rest/api/3/issue'
HEADERS = {
"Accept": "application/json",
"Content-Type": "application/json"
}
PARAMS = {
'jql': JQL_QUERY,
'fields': 'key',
'maxResults': 1000
}
def fetch_issue_keys():
issue_keys = []
start_at = 0
while True:
response = requests.get(SEARCH_URL, headers=HEADERS, params={**PARAMS, 'startAt': start_at}, auth=HTTPBasicAuth(LOGIN_USER_EMAIL, API_TOKEN))
response.raise_for_status()
data = response.json()
issues = data.get('issues', [])
if not issues:
break
issue_keys.extend(issue['key'] for issue in issues)
start_at += len(issues)
if start_at >= data['total']:
break
return issue_keys
def convert_time_to_minutes(time_str):
hours = sum(int(part[:-1]) * 60 for part in time_str.split() if 'h' in part)
minutes = sum(int(part[:-1]) for part in time_str.split() if 'm' in part)
return hours + minutes
def fetch_total_logged_time(issue_keys):
total_time = 0
for issue_key in issue_keys:
response = requests.get(f'{WORKLOG_URL}/{issue_key}/worklog', headers=HEADERS, auth=HTTPBasicAuth(LOGIN_USER_EMAIL, API_TOKEN))
response.raise_for_status()
worklogs = response.json()['worklogs']
for worklog in worklogs:
if worklog['author']['emailAddress'] == SEARCH_USER_EMAIL:
total_time += convert_time_to_minutes(worklog['timeSpent'])
return total_time
if __name__ == '__main__':
issue_keys = fetch_issue_keys()
total_time = fetch_total_logged_time(issue_keys)
print(f'\nTime logged is {total_time}m\n')