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
Community showcase
Published in Off-topic

Run into these Solution Partners at Atlassian Open

Hey there Community! Atlassian Open is kicking off in less than a month and we can't wait to touch down in Vienna, Sydney and Boston. This is an opportunity to create the future of teamwork with ...

82 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