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,368,408
Community Members
 
Community Events
168
Community Groups

Transfer attachments across Jira Cloud Instances via API

jiraone.jpg

One of the daunting things to do during a Cloud Migration from another Cloud Instance is usually the attachments. How do I transfer my attachments from one Jira instance to another? Well the simple answer would be, to use the Jira REST API, but how do you actually achieve this across multiple projects?

And here's where jiraone comes in, which is a REST API implementation of Jira and it helps solves problems like this one. All you simply need to do is download the library from pip as it's written in python.

pip install jiraone

Then you can be able to access all the methods, functions and classes available on it.

To give you an example of transferring attachments from one instance to another, all you need to do is

Firstly: Download a file report of the attachment structure into a flatten state, which contains the name of the file, the attachment url, the issue key where these files are located.

from jiraone import LOGIN, PROJECT

user = "email"
password = "token"
link = "https://sourceinstance.atlassian.net"
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
    # you can use any valid jql query
    jql = "project%20in%20(COM%2C%20PYT)%20order%20by%20created%20DESC"
    PROJECT.get_attachments_on_projects(query=jql)

Use a valid JQL to output the required project in order to get a csv file of the required data structure. Once this call completes, you will get a result output in csv format.

Secondly: Use the data structure that you got, to transfer the attachment into a target instance. Please take note that the Project must be created first on the target instance with the same corresponding issue keys and you must have the needed permissions on the project. That way the attachments are uploaded to the right issues on the target instance.

from jiraone import LOGIN, PROJECT


user = "email"
password = "token"
link = "https://targetinstance.atlassian.net"
LOGIN(user=user, password=password, url=link)


if __name__ == '__main__':
    # the output of the file would be absolute to the directory where this 
    # afterwards, you can use the below method to move attachments across instances without downloading it
    PROJECT.move_attachments_across_instances()

If you're using your own file structure, let's say a csv file. you need to identify the index of the attachment. For this, 3 keyword args are used. key=0, attach=1, and file=2 -> all requires an integer value which correspond to the index of the csv column length.

 PROJECT.move_attachments_across_instances(attach_file="new.csv", key=0, attach=1, file=2)

With the above, you can easily move attachments from one Jira cloud instances to another, without downloading the attachments to your local device. 

10 comments

Pramodh M Community Leader Jan 17, 2021

Thank You @Prince Nyeche 

This helps !

Pramodh

Are the original users who uploaded the attachments, and the attachment creation dates, preserved?

No it doesn't let you do that yet. would be good if the api allows that in the body parameters.

Taranjeet Singh Community Leader Jan 22, 2021

This is really useful feature! Thanks for sharing this @Prince Nyeche !

Glad to hear it helps.

Hi Prince,

It's throwing me the following error. I can confirm that I have valid jql passed as input.

Capture.PNG

Please suggest. Thanks. 

Hey @Manikanta 

This problem seems to happen on only windows OS and the version of python seems to vary. Your python version should be version 3.9.x and above. 

Hi Prince,

Yes I'm on windows but upgraded to python 3.9.8 and still facing the issue. Is there something that I need to change on the source code?

Thanks,

Mani

You can open a bug request here and I can look into it as soon as possible. I believe it has something to do with the regular expression but I need to examine it further to know exactly. In the meantime, if it's urgent you can spin up a linux virtual machine on your windows. That way you should be able to use the same jiraone version to perform the attachment transfer. As the same code works for unix-like system (macOS and linux alike) without any issue.

Comment

Log in or Sign up to comment
TAGS

Atlassian Community Events