It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

REST API to download attachment related to issue

Pranav Gupta Jul 05, 2016

Hi,

I am trying to download attachment. I've got url to attachment but I am not sure how to proceed to download attachment from the following url. Could anyone plz provide me the python code.

https://<jira_server>rest/api/2/attachment/266746

1 answer

0 votes
Jeff Sinclair Atlassian Team Aug 09, 2016

You can use JIRA Python to do this.

Here is my example code:

jira = JIRA(basic_auth=(un, pwd), options={'server': server})

issue = jira.issue(issuekey, fields='summary,comment,attachment')

for attachment in issue.fields.attachment:
	with open('dl-%s' % (attachment.filename), 'wb') as file:
		file.write(attachment.get())

 

This script will cycle through all the attachments on a given issue, and download them one by one to the current directory (prefixing each with the string "dl-").

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

9,986 views 46 44
Read article

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