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

Attaching CSV file to issue jira rest api python

Sarah Godine January 4, 2021

Note: I am using python.

I am trying to create an issue using the API that has a CSV file as an attachment.

I have done some research and it seems I need to create the issue, then update the issue and add the attachment.

I am able to create an issue with no problem. However, when I go to add the CSV file, I am getting a 404.

Here is my code for adding the csv to my issue. I store the id of the issue I created into a dataframe. My auth is correct - I have just ommitted it for this post.

 

 

files = {'file': open('myfile.csv', 'rb')}


url="https://mydomain.atlassian.net/rest/api/2/"+str(df.iloc[0]['id'])+"/attachments"


headers = {
"Accept": "application/json",
"Content-Type": "multipart/form-data",
"X-Atlassian-Token": "no-check"
}


response = requests.request(
"POST",
url,
headers=headers,
auth=auth,
files=files
)

 

Any help would be greatly appreciated! 

2 answers

1 accepted

1 vote
Answer accepted
Sarah Godine January 5, 2021

I found the solution for others reference. This is the full code that is used with the exception of omitting the auth values.

 

files = {
'file': (myfile.csv, open(myfile.csv, 'rb')),
}


url="https://mydomain.atlassian.net/rest/api/2/issue/{id}/attachments"


headers = {
"Accept": "application/json",
"X-Atlassian-Token": "no-check"
}


response = requests.request(
"POST",
url,
headers=headers,
auth=auth,
files=files
)

 

The first issue was I needed to add "/issue/" into my URL before the id of the issue. Secondly, I needed to remove "Content-Type": "multipart/form-data" from my header values.

 

I hope this helps others!

Do you know how to use python to attach a pdf file into a jira issue?

0 votes
Prince Nyeche
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 4, 2021

Hi @Sarah Godine  

there's a framework called pyjira which provides an easier method to create and attach an attachment easily into an issue in python. Something worth considering, however your example code here is incomplete and guessing what you're trying to do isn't really troubleshooting. I will suggest you show a proper snippet of your code and what you've done so far. something you know you can publicly display here on community and we can examine it to see what's wrong with it and expand on it if necessary.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events