How to get issue history with JIRA API?

Elshy February 3, 2020

Hi,

I am a very new user to Jira and Jira API. I am required to export from JIRA website a bunch of issues history in an excel file. 

I have read in many forums that you need whether an extension or that I could write a request in Jira Api. As i am very new to Python and programming, i don't know how to write such a program using the url to extract all the issue history, I have tried but it is not working.

Could you please help me with the issue? 

PS: I want the issue history in order to figure the number of ticket reopening and there status (closed, resolved and closed)

3 answers

1 vote
Alexander Scholz November 10, 2023

Hey all, 

we were searching for a solution to exctract the full history of all issues via REST API to a Qlik Cloud project. 

 

Since there is no possibility, here is a ticket to implement the function. 

Ability to extract issue history of all issues via API 

Please vote. :-)

Thanks

0 votes
Caio Vinicius de Queiroz Luz October 21, 2021

@Elshy do you can do it?

Can you share your solution, please?

Yuliia_Borivets__SaaSJet_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 22, 2021

Hi @Caio Vinicius de Queiroz Luz 

If you'd like to export issue history for a list of issues, you can try the Issue History add-on. It provides a ticket history report of all changes that have been made in the selected list of issues. There is an option for export here.

issue history export.jpg

The app is developed by my team, so let me know if you have any questions.

0 votes
Mohamed Benziane
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 13, 2020

Hello @Elshy 

Welcome to the community

Are you sur that you need to use API for this. It seems that you just need to write a JQL to be able to find the number of ticket.

Closed ticket :

project = "ABC" ans status in ("Closed")

 Resolved ticket :

project = "ABC" and resolution in ("Resolved")

 reopened ticket :

project = "ABC" and status changed from "Closed" to "Reopen"

 You can add date to narrow your search :

project = "ABC" ans status in ("Closed") and createddate >=StartofMonth(-1) and createddate <= EndofMonth(-1)

This query will find all issue closed in the project ABC that where created the previous month.

With JQL you will be able to export your result in CSV.

 

https://confluence.atlassian.com/jirasoftwareserver086/saving-your-search-as-a-filter-990555095.html

https://confluence.atlassian.com/jirasoftwareserver086/working-with-search-results-990555156.html

 

Hope this helps

Elshy February 17, 2020

Hi,

 

Thanks for your kind help and sorry for my late answer.

Unfortunately i already tried this, it worked but it does not give me what i want. What i am looking for is how much items have been reopened (what the Jira query gives) but also HOW MANY times an item as been reopened (most of my items have been reopened twice), as i have almost 500 items i would like to avoid doing it manually... My final aim is to calculate a reopen rate....

 

If you have any idea on how to help with these precision i would be really happy :)

Elshy February 17, 2020

Here is the python i tried to write but as i am very new to python and programming it kept failing hahaha...

 

 

import requests
import json
from openpyxl import load_workbook
import html
from openpyxl.styles import PatternFill, Border, Side, Alignment, Protection, Font, NamedStyle
import datetime
from openpyxl.styles.colors import ColorDescriptor, Color
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile


headers = {
'proxy-authorization': 'Basic UElENjNEQjpQYXNzd29yZDEyMzQ=',
'authorization': 'Basic UElENjNEQjpQYXNzd29yZDEyMzQ='
}

#EXCEL CREATION
Today = str(datetime.datetime.now()).split(".")[0].replace(':', '_')
wb = load_workbook(filename='C:/Users/ESABIRB/Desktop/Issuehistory.xlsx')
wb.save(Excel)

wb = load_workbook(Excel)
EX = wb['JiraData']

#JIRA API REQUEST
r = requests.get('https://jira-dsc.apac.bg.corpintra.net/rest/api/2/search?XXXXXXXXXlink', headers=headers, verify=False)
issue = requests.get('https://jira-dsc.apac.bg.corpintra.net/browse/issue', headers=headers, verify=False, expand='changelog')
#issue = r.issue('NGT-25021', expand='changelog')
changelog = issue.changelog

for history in changelog.histories:
for item in history.items:
if item.field == 'status':
print ('Date:' + history.created + ' From:' + item.fromString + ' To:' + item.toString)

Like Matthew Korich likes this
Mohamed Benziane
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 17, 2020

Hello @Elshy 

Here a code, i used the jira modul for python :

from jira import JIRA
jira_server = JIRA(basic_auth=("username","password"), options={'server''https://URL'})
issues_Jql = jira_server.issue('your issue',expand='changelog')#pass one issue at the time  
#print(issues_Jql)
changelog = issues_Jql.changelog
count = 0
for history in changelog.histories:   
for item in history.items:        
if item.field == 'status':            
if item.toString == "Reopened":                
count = count + 
1            
print(count)   
Like # people like this
Elshy February 17, 2020

Hi, 

thanks again for this very useful help. One last question do you know what i should put instead your issue to have the number for all issues?

 

Thanks a lot :)

Mohamed Benziane
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 18, 2020

Hi, you need something like that:

dictionnary = {}
for
 i in jql_search:    
count = 
0    
for history in jira_server.issue(i.key, expand = 'changelog').changelog.histories:              
for item in history.items:                   
if item.field == 'status'                       
if item.toString == "Done":
  
                            
count += 
1                            
dictionnary[i.key] = count      

Hope this helps

Like # people like this
Gopinath R August 12, 2022

Hi - My name is Gopinath. RG, i am new to python i need help in pulling histories of all jira issues where item.field = status, i am using below code

from jira import JIRA
from pandas import pandas as pd
jiraOptions = {'server': "https://domain.atlassian.net"}
jira = JIRA(options=jiraOptions, basic_auth=("username", "password"))
Status_History = pd.DataFrame(columns=['Key','Changed Date','Status From','Status To'])

 

jql='project in (project) AND (component not in (TEST_DATA) OR component is EMPTY) AND "Team[Team]" in (1694, 1695, 1696, 1697) ORDER BY project DESC, due DESC, key DESC, status DESC, created ASC, priority DESC'
dictionnary= []
for singleIssue in jira.search_issues(jql_str=jql, expand='changelog'):
count = 0
issue = jira.issue(count, expand='changelog')
changelog = issue.changelog
for history in changelog.histories:
for item in history.items:
if item.field == 'status':
count += 1
Status_History.loc[len(Status_History.index)] = [issue.key,history.created,item.fromString,item.toString]

 

i have some 5500 issues, but i am getting only 31 results, once i execute the above code, can you please help me to get all histories of all issues. Thanks.

Suggest an answer

Log in or Sign up to answer