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

Attaching CSV file to issue jira rest api python Edited

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

0 votes
Answer accepted

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!

0 votes
Prince Nyeche Community Leader Jan 04, 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
Community showcase
Published in Jira Service Management

Why upgrade to Jira Service Management Premium?

We often have questions from folks using Jira Service Management about the benefits to using Premium. Check out this video to learn how you can unlock even more value in our Premium plan.  &nb...

163 views 0 4
Read article

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