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

How to upload attachment to an Issue using the REST API in Python??

Jagruthi k Aug 10, 2015
I want to upload an attachment to an Issue in Jira using the Rest API. How can I do the following in Python.
curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt" http://myhost/rest/api/2/issue/TEST-123/attachments

3 answers

1 accepted

5 votes
Answer accepted
Rafael Sperafico Atlassian Team Aug 17, 2015

Hello 

Thank you for your question.

Please, run the following in Python:

# ===============
# greeting.txt
# ===============
hello, world
 
# ===============
# upload.attachment.py
# ===============
import requests
import json


# [JIRA-BASE-URL], i.e.: http://localhost:8080
# [ISSUE-ID], i.e.: ATT-1
url = '[JIRA-BASE-URL]/rest/api/2/issue/[ISSUE-ID]/attachments'
headers = {"X-Atlassian-Token": "nocheck"}
# please uncomment to attach external file
files = {'file': open('greeting.txt', 'rb')}


# upload file to issue
# [USERNAME], i.e.: admin
# [PASSWORD], i.e.: admin
r = requests.post(url, auth=('[USERNAME]', '[PASSWORD]'), files=files, headers=headers)
print(r.status_code)
print(r.text)

If you find this answer useful, I would kindly ask you to accept it so the same will be visible to others who might be facing the same issue you have inquired.

Thank you for your understanding.

Kind regards,
Rafael P. Sperafico
Atlassian Support

0 votes

Hi Jagruthi, 

I believe the answer you are looking for might be related on this article:

https://docs.atlassian.com/jira/REST/6.2/#d2e2310

 

Cheers,

Rodrigo Silva

Jagruthi k Aug 10, 2015

Is it possible to do it in python without using the curl.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Statuspage

⭐️Would you recommend Statuspage? Leave a (honest!) review. ⭐️

Hi Community friends, We're working on sourcing more reviews on Capterra – a popular software review site –  to help teams like yours make more informed decisions when choosing an inc...

82 views 3 5
Join discussion

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