Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I add attachments without permission error?

Marc LaBelle February 20, 2019

When I try to add an attachemnt with the API (code below), I get the error:

"You do not have permission to create attachments for this issue."

url = self.base_http_url + 'rest/api/2/issue/' + issue_id + '/attachments'
headers = {'X-Atlassian-Token': 'no-check'}

r = requests.post(url, auth=self.auth, headers=headers, files=files)

 Why am I getting this error? The user is admin and can successfully do everything else.

1 answer

0 votes
Marc LaBelle February 20, 2019

I apparently forgot to enable attachments on my dev machine, but now I'm getting a 200 status code, but response is empty and the file is not attached.

Marc LaBelle February 20, 2019

So, apparently the file in the request has to have the "name" "file":

url = self.base_http_url + 'rest/api/2/issue/' + issue_id + '/attachments'
headers = {'X-Atlassian-Token': 'no-check'}

files = {}

for file in attachments:
files['file1'] = open(file, 'rb')

r = requests.post(url, auth=self.auth, headers=headers, files=files)

 

But I can't upload multiple files like this...

Marc LaBelle February 20, 2019

I've given up and will send one file at a time.

def add_attachment(self, issue_id, attachments):

# add attachments to Jira issue
url = self.base_http_url + 'rest/api/2/issue/' + issue_id + '/attachments'
headers = {'X-Atlassian-Token': 'no-check'}

files = {}
r = []

if len(attachments) < 1:
r.append('ERROR: No files attached')

for file in attachments:
files['file'] = open(file, 'rb')
r.append(requests.post(url, auth=self.auth, headers=headers, files=files))
files['file'].close()

return

Suggest an answer

Log in or Sign up to answer