Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,204
Community Members
 
Community Events
165
Community Groups

Extracting complete issue history via API

history.jpeg

There are a lot of things that can be said when you have a history of such information. Given that Jira is a great piece of software, it provides a means whereby there's data integrity when something is changed within a project. The issue history feature by far is one of the most vital features that Jira has to offer. The complexity involved in recording data and the changes that took place makes it an integral part that shouldn't be easily manipulated.

Hence, I believe one of the fundamental things to keep in mind while moving from server to cloud is the ability to retain issue history. However this is a very complex process to do and in most cases, you end up not transferring this data due to the complexity involved.

 

Alternatively, it doesn't mean you can't extract such information from either a server to cloud instance or vice versa or even a cloud to cloud instance of Jira. The way to go about it, is to use Jira's REST API and the end result is an output in a CSV file which can be viewed from any spreadsheet application.

issue.pngMost of the API related instructions here are based on python examples using a specific package called jiraone (can be installed using pip install jiraone). Which can simply output a report file in CSV format. Example for Jira server instance given below

from jiraone import LOGIN, PROJECT

user = "username"
password = "password"
link = "https://yourinstance.atlassian.net"
LOGIN.api = False  # comment out line, if you want to extract history from a cloud instance
LOGIN(user=user, password=password, url=link)

if __name__ == '__main__':
    # the output of the file would be absolute to the directory where this python file is being executed from
    jql = "project in (PYT) ORDER BY Rank DESC"  # A valid JQL query
    PROJECT.change_log(jql=jql)

With the above, you will get a complete extract of all issue history in CSV format within the specified project listed in the JQL variable.

16 comments

M Amine Community Leader Jun 09, 2021

Very interesting content

Hi Prince,

I have used this code and it runs well and gets the history of issues but at a certain point I get the error: "expecting value line 1 column 1 (char 0)" which is when the code stops running. Can I please get some help on how to go about fixing this error so that it does not interrupt the code from getting all of the issue history? Your assistance will be appreciated.

Hi @Tristan Munthree 

Please can you create an issue on the package in Github with the stack trace error, so I can trace where the error is coming from?

Hi @Prince Nyeche 

I have just created an issue with attachments showing the error, thank you for your prompt response.

Like Prince Nyeche likes this

Where should I run the script?

Can I do it directly on ScriptRunner?

No, this is a python script. You will need to install python on your device and run it from your terminal or if you have an IDE, you could run it from there too. 

@Prince Nyeche 

Thanks for your comments, I have tested the script and it works but does it have export limits?
I have to export the information of more than 1000 records, is this possible?
What do I have to modify in the code or where can I consult more information to achieve this?

Yes, there's no export limit. You can go to the doc https://jiraone.readthedocs.io

Hi @Prince Nyeche

When I run the code I get the error below

UnicodeEncodeError: 'charmap' codec can't encode character '\x95' in position 1114: character maps to <undefined>

I checked the issue and this happens because the custom field (objective) has bullets as example below

image.png

Do you know how can I solve this?

Hey @Miguel Angel Velazquez Solis 

It's suppose to try to convert that using utf-8 character encoding as that's the default on unix-like systems. However, I think if you're using windows this has to be explicitly mentioned when writing to a file. I'll push an update about this problem. Please can you create an issue here with the error that you received and I'll follow up with a resolution in the next update.

Hi @Prince Nyeche

Thank you so much 

I have already created the ticket in github.

Regards

Hi,

How are credentials passed to the Project object?

The code above uses the `token_session` to initialize the `auth_request` attribute of the LOGIN class. But inside the PROJECT class the LOGIN class isn't ever initialized and no parameters are passed from the instantiated LOGIN class to the environment or PROJECT class in any way. 

How is this supposed to work?

I'm getting this error:

JiraOneErrors: <JiraOneError: Authentication failed. Please check your credentials.>
 

Thanks,
Andrew

Hey Andrew,

Great question. To get the authentication to work, you need to instantiate the LOGIN  alias or class once hence the call

# previous login variables
LOGIN
(user=user, password=password, url=link)

Once that is done, you can access all the objects accessible to that class from anywhere within the code. The LOGIN alias is a global object for authentication that is used with the classmethod for Jira's API url called endpoint. So since the LOGIN performs authentication and HTTP requests, we can do something like after it's instantiated.

LOGIN.get()

And since this is global when combined with the classmethod for each endpoint alias or class. This passes the entire session plus the endpoint class to the HTTP methods extracting the API contents. The PROJECT alias mostly being static doesn't really need instantiation. However, note that it is already instantiated automatically hence it can be called directly. With the above when combined together, each session is passed sequentially and the session lives in memory until the script is terminated or you terminate the connection or whatever objects you've called. Now, coming to why you get the error, there could be a number of reasons but the only thing that can cause that error is either a wrong email address or token (if on Jira cloud) or a wrong username or password (if on Jira server or DC).

If you're on Jira server or DC and using PAT, I think this might not work as I didn't test such authentication mechanism. So it's best to stick with username and password. OAuth 2.0 works as well but it was only tested on Jira cloud, so its mechanism might not work for Jira server or DC. Let me know if that answered your question.

Like Andrew Rainboldt likes this

Hi, 

Thanks for the quick response. Now I see the way LOGIN is created, via this

LOGIN = InitProcess()  

 and then re-instantiated when called. 

Thanks for the explanation.

Regarding the error, I'm just trying to access my company jira server with username and password as indicated in the example. 

I'm running out of Jupyter, perhaps something odd is happening there, but l've switched to cmd and the same error is coming up

Thanks

Before calling the LOGIN alias since you're connected to a Jira server instance do the below

# previous login variables
LOGIN.api = False
LOGIN
(user=user, password=password, url=link)

As Jira server still uses v2 of Atlassian API. The attribute `LOGIN.api` changes the endpoints from api `v3` which works on cloud to `latest` which works on Jira server or DC. Probably that's why the auth keeps failing because it cannot connect at all.

Hey Prince,

thanks, authentication still doesn't work. It could be to do with the way my company manages accounts. 

 

Thanks anyway

Comment

Log in or Sign up to comment
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you