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

How do I add a component to an issue using jira-python?

How do I add a component to an issue using python-jira?

Assuming that I have the component name and the issue key, how do I add this component to the issue.

The issue may already have a compoment assigned to it and I do not want to loose it.

2 answers

Below is how I was able to use jira-python to create and issue and add a component. I figured this out by taking a look at the REST API for JIRA. :

jira.create_issue(project={'key': project_id}, summary=ticket_summary,
                                     description=ticket_description, issuetype={'name': ticket_issue_type},
                                     components=[{'name': 'Application Slow'},], parent={'id': new_issue_key}, customfield_10101=termination_change_date,
                                     )

I don't believe they have built this into the API. If they have, I'm not sure if the syntax would be any more managable than a straight-up REST call

Using the requests module:

#!/usr/bin/python

import requests

auth=requests.auth.HTTPBasicAuth(USERNAME, PASSWORD)
component = 'COMPONENT'
url='http://YOUR.JIRA.URL'
issueKey='PROJECT-001'
headers={'Content-Type': 'application/json'}

params = '{"update" : {"components" : [{"add" : {"name" : "%s"}}]}}' % component
restUrl = '%s/rest/api/2/issue/%s' % (url, issueKey)
response = requests.put(restUrl, data=params, auth=auth, headers=headers)

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published 5 hours ago in Off-topic

Teams behind the teams - Your nominations please!

Teams do amazing things together. We’ve talked about the myth of the lone genius and how everything is actually the result of teamwork. You might be thinking, What about a novelist writing, say, Th...

47 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you