Creating and cloning Jira issues with Python: Setting paths and getting IDs

I’m trying to make Jira issues using Python. I found some code online but I’m confused about a few things.

  1. Where does the issue end up? Is there a way to set the path or repository?
  2. Can I get the CETM ID of the new issue?
  3. Is it possible to clone an issue and get its CETM ID too?

Here’s a code example I’m working with:

import jira_connector

def create_jira_task(project_id, summary, description, task_type):
    task_info = {
        'project': {'id': project_id},
        'summary': summary,
        'description': description,
        'issuetype': task_type
    }
    return jira_connector.make_task(task_info)

new_task = create_jira_task(456, 'Bug fix', 'Fix login error', 'Bug')

Can someone help me understand how to do these things? Thanks!

hey, i’ve worked with jira api before. for your questions:

  1. issues go to the project you specify (like 456 in ur code)
  2. to get the id, modify ur code to return the response from the api call
  3. yeah, u can clone issues. use the /rest/api/2/issue/{issueIdOrKey}/clone endpoint

hope that helps! lmk if u need more info

I’ve worked extensively with the Jira API, so I can shed some light on your questions.

When you create a Jira issue, it’s associated with the project you specify in your code (project 456 in your example). Jira doesn’t use traditional file paths or repositories. Instead, issues are organized within projects and can be further categorized using components, labels, or custom fields.

To get the ID of a newly created issue, you’ll need to capture the API response. You can modify your code like this:

new_task = jira_connector.make_task(task_info)
issue_id = new_task[‘id’]

As for cloning, Jira does provide an API endpoint for this. You’d use a POST request to ‘/rest/api/2/issue/{issueKey}/clone’. The response will include the new issue’s ID.

Remember to handle errors and use appropriate authentication when making API calls. Let me know if you need more specific guidance!

Having worked with Jira and Python for a while, I can share a couple of insights that may help. When you create an issue in Jira, it gets associated with the project you specify in your task data (for example, project 456 in your code snippet). Even though Jira doesn’t set a file or repository path per se, you can manage issues better by applying appropriate components or labels.

For retrieving the issue ID, you need to modify your API call to return the full response. Once you capture the response, you can extract the ID with something similar to:

new_task = create_jira_task(456, 'Bug fix', 'Fix login error', 'Bug')
issue_id = new_task['id']

Regarding cloning, Jira offers endpoints to clone an issue which essentially creates a new issue based on the original. Here’s a simplified example:

def clone_issue(issue_key):
    clone_data = {'to': {'project': {'id': 'target_project_id'}}}
    response = jira.post(f'/rest/api/2/issue/{issue_key}/clone', json=clone_data)
    return response.json()['id']

This example clones the issue and returns the new issue’s ID, but remember to implement proper error handling and confirm the target project details as needed.