Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Attachment upload rest API

Hello,

 

I am probably being silly but following the Jira Cloud Rest API documentation (Python) for uploading an attachment to an issue I can't see where to specify the file - the below is the example code. Like I said might just be a long day but I am pulling my hair out!

 

# This code sample uses the 'requests' library: # http://docs.python-requests.org import requests from requests.auth import HTTPBasicAuth import json url = "https://your-domain.atlassian.com/rest/api/3/issue/{issueIdOrKey}/attachments" auth = HTTPBasicAuth("email@example.com", "<api_token>") headers = { "Accept": "application/json" } response = requests.request( "POST", url, headers=headers, auth=auth ) print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))

 

Thanks

Peter.

3 answers

Check this Link out - it might have the information you need to specify the file location within your script

https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-upload-attachment-to-an-Issue-using-the-REST-API-in/qaq-p/464045

0 votes

Hi @Peter Griggs ,

The API uses standard multipart form data uploading. If you're using Python, that means using the "files" argument documented here: https://requests.readthedocs.io/en/latest/api/

I haven't used Python in ages, but my reading of the docs is that "files" should be a dictionary. The key must be "file" (the name of the parameter in the Atlassian API docs) and the value must be a tuple: (your filename, your fileobj).

Please also remember to set the "X-Atlassian-Token" header to "no-check" in your "headers" argument.

Thanks will try in the morning. I think the documentation and example needs some work. It really isn't clear.

I'm still no further forward, also "no-check" isn't show in the example in the documentation. I am really chasing my tail.

John Agan Atlassian Team Dec 01, 2020

Hey @Peter Griggs

I just happened upon this thread and haven't tested this answer personally, but I think this example may help:

 

import requests

url = "https://your-domain.atlassian.com/rest/api/3/issue/{issueIdOrKey}/attachments"

# Parse authentication credentials
auth = requests.auth.HTTPBasicAuth('USERNAME','PASSWORD')

# JIRA required header
headers = { 'X-Atlassian-Token': 'no-check' }

# Setup multipart-encoded file
files = [ ('file', (filename, open('/path/to/file.txt','rb'), mime_type)) ]

# Run request
r = requests.post(url, auth=auth, files=files, headers=headers) 

Suggest an answer

Log in or Sign up to answer
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