Search code examples
pythonjirajira-rest-apiissue-trackingpython-jira

How to assign id to a created issue with jira python?


I am using jira python to create issues through their REST api, but in the "fields" dictionary for the "project" key's dictionary, I am running into an issue when I try using "id" or "name" as keys, but it works with the "key" key.

So, this works:

'project': {'key': 'ORION'}

But, when I try using the other keys provided in the jira-python documentation such as:

'project': {'name': 'ORION-777'}

or

'project': {'id': 777}

or

'project': {'id': '777'}

It does not work. I am getting an error that says:

response text =
{
    "errorMessages": [],
    "errors": {
        "project": "project is required"
    }
}

I want to specify the id so that I don't keep creating issues for the same bug over and over. Any guidance is welcome. Thanks!


Solution

  • Following the documentation link that you provided, you can create an issue in the following ways:

    new_issue = jira.create_issue(project='PROJ_key_or_id', summary='New issue from jira-python',
                                  description='Look into this one', issuetype={'name': 'Bug'})
    

    or

    issue_dict = {
        'project': {'id': 123},
        'summary': 'New issue from jira-python',
        'description': 'Look into this one',
        'issuetype': {'name': 'Bug'},
    }
    new_issue = jira.create_issue(fields=issue_dict)
    

    You can you a project key, name or ID.

    To get the name or key, go the "Project settings" of your project then click on "Details" (you need to have the permission to see these settings).

    To see the ID without making any rest query, go again in the "Project settings" page then mouse-over on details and you can view the project id in the navigation bar at the bottom of browser (i.e. pid=12345)

    With this information you should able to create the issue using name, key or ID of your project.