Creating multiple JIRA subtasks for Issues without subtask using REST API

Posted: March 7, 2018 in Linux, Scripts

In previous post we created only one subtask for one issue. What in situations when need to create subtasks for issues without subtasks ?.Unfortunately, there is no native  JQL function that can verify if an issue has or hasn’t a subtask.JIRA has third party add-ons that extend Jira’s functionality.
This python script will return JIRA key’s for tasks without subtasks and create subtask for it:

import sys
import json
import re
import requests
import os
import urllib2
import argparse
from json_tricks import dump,dumps

password = str(sys.argv[1])

headers = {
'Content-Type': 'application/json',

params = (
('jql', 'project="Technology" AND summary~"New User*" AND issuetype="Task" AND status!="DONE"'),

response = requests.get('', headers=headers, params=params, auth=('user', password))

datapath = '/var/lib/rundeck/1.json'
data = json.load(open(datapath))

for issue in data['issues']:
if len(issue['fields']['subtasks']) == 0:
        line = issue['key']
        headers = {"Content-Type": "application/json"}
        data = {"fields": {"project": {"key": "TECH"},"parent": {"key": line.rstrip()},"summary": "Create user account in Local AD. ","description": "Create user account in Local AD.",
       "issuetype": {"name": "Sub-task"},"customfield_10107": {"id": "10400"}}}
        response ="",
        headers=headers,data=json.dumps(data),auth=('user', password))


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s