6/10/2020 Solved: How to upload attachment to an Issue using the RES...
Atlassian stands in solidarity in the fight against the oppression of Black people. Read our
×
founder blog here.
Explore
Ask the community Search Sign up Log in
Community / Answers Developer Questions / Questions / How to upload attachment to an Issue using the REST API in Python??
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 "[email protected]"
http://myhost/rest/api/2/issue/TEST-123/attachments
Answer Watch • Like Be the first to like this
3 answers 1 accepted
Comments for this post are closed
Community moderators have prevented the ability to post new answers.
Post a new question
7votes Answer accepted
rsperafico ATLASSIAN TEAM
Aug 17, 2015
Hello
Thank you for your question.
Please, run the following in Python:
# ===============
# greeting.txt
# ===============
https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-upload-attachment-to-an-Issue-using-the-REST-API-in/qaq-p/464045 1/5
6/10/2020 Solved: How to upload attachment to an Issue using the RES...
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
Nathaniel Miller
Aug 16, 2019
Great post, made the difference for my efforts. The one thing I would mention is that at least for me (2019, Python2,
CentOS 7) I had to do the following for the authentication to work:
credentials = requests.auth.HTTPBasicAuth('[USERNAME]','[PASSWORD]')
r = requests.post(url, auth=credentials, files=files, headers=headers)
Like
Reply
1vote
Rodrigo Silva
Aug 10, 2015
Hi Jagruthi,
I believe the answer you are looking for might be related on this article:
https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-upload-attachment-to-an-Issue-using-the-REST-API-in/qaq-p/464045 2/5
6/10/2020 Solved: How to upload attachment to an Issue using the RES...
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.
Like
Reply
0votes
Jaime Silveira ATLASSIAN TEAM
Aug 11, 2015
Here's an equivalent of curl in python (I didn't test it, by the way):
http://stackoverflow.com/questions/2667509/curl-alternative-in-python
These are also useful:
https://confluence.atlassian.com/display/JIRA061/How+to+attach+an+attachment+in+a+JIRA+issue+using+REST
+API
https://confluence.atlassian.com/display/JIRAKB/Bulk+import+attachments+to+JIRA+issues+via+REST+API
Kind regards,
Jaime Kirch da Silveira
Atlassian Cloud Support
Reply
Still have a question?
Get fast answers from people who know.
Sign up for free Log in
Answers Developer Questions
TAGS
attachment cloud jira jira-cloud python rest-api
https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-upload-attachment-to-an-Issue-using-the-REST-API-in/qaq-p/464045 3/5
6/10/2020 Solved: How to upload attachment to an Issue using the RES...
Related Community content
Issues attaching pictures using Confluence REST AP...
Upload attachment to bitbucket server with REST AP...
Cannot update Jira issue fields via REST API (in P...
Adding watchers using REST API returns 404
Upload Attach - API Token - Java
Ask Me Anything: All things DevOps! Coming June 9th.
Matt Ryall, Head of Product, DevOps at Atlassian is here to answer your questions about DevOps practices and
the latest features to help your team succeed.Ask your question and upvote now!
Ask a question now
COMMUNITY SHOWCASE
Ben_Thoma
Published in Training & Certification
Atlassian University Live: How to earn your first Atlassian credential
Atlassian University Live webinars provide you and your teams with the chance to strengthen your Atlassian
product skills, and learn directly from Atlassian experts. Learn how to earn our newest A...
144 views 3 10
Read article
https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-upload-attachment-to-an-Issue-using-the-REST-API-in/qaq-p/464045 4/5
6/10/2020 Solved: How to upload attachment to an Issue using the RES...
Community Events
Connect with like-minded Atlassian users at free events near you!
Find events near me
FAQ Community guidelines Privacy policy Terms of use © 2020 Atlassian
https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-upload-attachment-to-an-Issue-using-the-REST-API-in/qaq-p/464045 5/5