How to create multiple sub-tasks from parent

Ron Arevalo
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 17, 2017

Hi there, I'm working with the JIRA rest API and I know how to create a task as well as a single subtask but I need to create 7 sub-tasks at once. 

 

def new_issue():
    issue = requests.post(main_url + create_issue, data=json.dumps(task_data), auth=(user, pw), headers=headers)
    print(issue.json())
    print(issue.json()['key'])
    sub_tasks = [
        {
            "fields":
                {
                    "project":
                        {
                            "key": "DEVO"
                        },
                    "parent":
                        {
                            "key": issue.json()['key']
                        },
                    "summary": "Collectors",
                    "assignee": {
                        "schema": {
                            "type": "user",
                            "system": "assignee"
                        },
                        "name": user,
                        "key": "assignee",
                        "operations": [
                            "set"
                        ]
                    },
                    "description": "STUF THAT I NEED TO DO",
                    "issuetype":
                        {
                            "name": "Sub-task"
                        }}},

 

The sub_tasks is a list of python dictionaries, I have tried to run a loop that would iterate through all of these and it does however, I get the following response: 

 

{'errorMessages': ['Can not deserialize instance of com.atlassian.jira.rest.v2.issue.IssuesUpdateBean out of START_ARRAY token\n at [Source: org.apache.catalina.connector.CoyoteInputStream@1874cde; line: 1, column: 1]']}

 

But I haven't found what that mean. If anyone knows that would be great! 

 

I've also tried using the bulk issues endpoint but I get an error message that reads: 

 

{'errorMessages': ['No issue data was provided by request'], 'errors': {}}


Thanks in advance! 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Niclas Sandstroem
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.
March 17, 2017

I'm not sure if this helps you but iteration should work. This is a simple bash-script doing that without a session but creates one each time.

generate_subtask()
{
cat <<EOF
{
    "fields":
    {
        "project":
        {
            "key": "JIRA"
        },
        "parent":
        {
            "key": "JIRA-1"
        },
        "summary": "Sub-task of JIRA-1",
        "issuetype":
        {
            "id": "5"
        }
    }
}
EOF
}
for i in {1..5}
do
curl -u user:password -X POST -H "Content-Type: application/json" --data "$(generate_subtask)" https://jira.domain.com/rest/api/2/issue/
done
TAGS
AUG Leaders

Atlassian Community Events