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 Friday in Agile

Are you a Jira Service Desk agent? We want to talk to you!

Are you a whiz at handling tickets and looking at how you can further optimize your workflow with automation? Do you tackle detailed customer support questions while simultaneously getting flooded wi...

42 views 0 2
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