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.
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.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.