How to create subtasks with jira-python ?

maxandersen April 16, 2013

How does one create subtasks with the jira-python library ?

2 answers

1 accepted

2 votes
Answer accepted
maxandersen April 16, 2013

The trick is that parent id is not the issue id, but the issue key and subtype has to be 'Sub-task'

For example:

rootnn_dict = {
    'project' : { 'key': 'JBIDE' },
    'summary' : 'Test auto created issue',
    'description' : 'Ignore this. will be deleted shortly',
    'issuetype' : { 'name' : 'Task' },
    }

rootnn = jira.create_issue(fields=rootnn_dict)

print("created " + rootnn.key)

rootnn_dict = {
    'project' : { 'key': 'JBIDE' },
    'summary' : 'Test child auto created issue',
    'description' : 'Ignore this child. will be deleted shortly',
    'issuetype' : { 'name' : 'Sub-task' },
    'parent' : { 'id' : rootnn.key},
    }

child = jira.create_issue(fields=rootnn_dict)

print("created child: " + child.key)

G V Shabareesh October 10, 2018

Still i am getting error with include all of these... the error is that the issue type and id is not

when i am creating a sub-task this is the error actually encountered me..

 

""Could not find issue by id or key.""

 

this is the main error i am getting please resolve it immediately pls waiting for it,... help me somebody.

Parker Van Dyk February 20, 2019

Please replace 

 'parent' : { 'id' : rootnn.key},

 with

 'parent' : { 'key' : rootnn.key},
Like # people like this
0 votes
Matt Doar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 16, 2013

See https://answers.atlassian.com/questions/49433/creating-sub-task-of-an-issue-using-rest-api for the fields to set and then use the regular create_issue() function.

maxandersen April 16, 2013

I figured it out. Had a bad delete that was failing covering up the error. i'll post answer.

maxandersen April 16, 2013

I tried this in many various combinations but no luck.

rootnn_dict = {

'project' : { 'key': 'JBIDE' },

'summary' : 'Test chfild auto created issue',

'description' : 'Igfnore this child. will be deleted shortly',

'issuetype' : { 'id' : '5' },

'parent' : { "id" : rootnn.key},

}

child = jira.create_issue(fields=rootnn_dict)

where rootnn.key is a valid parent *key*, not just id as stated on your link.

But the last child creation fails.

G V Shabareesh October 10, 2018

when i am giving issue type as 5 it is saying that give the proper issue type..please help me.

Suggest an answer

Log in or Sign up to answer