You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
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.
Check this Link out - it might have the information you need to specify the file location within your script
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks - I have had a look but it's not referenced here in the documentation: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks will try in the morning. I think the documentation and example needs some work. It really isn't clear.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm still no further forward, also "no-check" isn't show in the example in the documentation. I am really chasing my tail.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.