How to Create Subtask using Rest API.

Raghuvamsi Uthpala May 19, 2014

I've used below command with no success. I couldn't create subtask using below syntax. Please help me in fixing this

Request:

curl -D- -u project-db:projectdbtest -X POST --data {""fields"":{""project"":{"key": "DT"},""parent"":{"key":"DT-33"},""summary"":"Test",""issuetype"":{"id":"53"}}} -H "Content-Type: application/json" http://jira2.com/rest/api/2/issue/

Response:

HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
X-AREQUESTID: 1381x497449x1
Set-Cookie: JSESSIONID=7E6AEAE7A75CF772B0F201417604AE51; Path=/; HttpOnly
X-Seraph-LoginReason: OK
Set-Cookie: atlassian.xsrf.token=AGWG-LFJC-4AYE-UW3X|f3114f62546ec709c9f262291fd2311a7d3f6fd8|lin; Path=/
X-ASESSIONID: nusqd4
X-AUSERNAME: project-db
Cache-Control: no-cache, no-store, no-transform
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 20 May 2014 06:01:16 GMT
Connection: close

{"errorMessages":["Unexpected character ('f' (code 102)): was expecting double-quote to start field name\n at [Source: org.apache.catalina.connector.CoyoteInputStream@596d22e; line: 1, column: 3]"]}

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
BenjiI
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.
May 19, 2014

Hi Raghuvamsi,

I stronly suggest you use a http REST client (like Google's postman Chrome plugin), because this tool makes you life much easier :)

In the following usecase I made a project with project key TEST. My jira instance is running on the localhost (base url: http://localhost:2990/jira). To create a subtask using REST do the following:

1) Create an issue to which you want to attach a subtask:

  • URL: http://localhost:2990/jira/rest/api/2/issue
  • Headers:
    • Content-Type: application/json
  • Make sure authentication is present in the header
  • Content:
    • {
          "fields": {
             "project":
             { 
                "key": "TEST"
             },
             "summary": "REST ye merry gentlemen.",
             "description": "Creating of an issue using project keys and issue type names using the REST API",
             "issuetype": {
                "name": "Bug"
             }
         }
      }

Result:

2) Create a sub-task and attach it to the issue from step 1:

  • URL: http://localhost:2990/jira/rest/api/2/issue
  • Headers:
    • Content-Type: application/json
  • Make sure authentication is present in the header
  • Content:
    • Content:
      
      {
          "fields":
          {
              "project":
              {
                  "key": "TEST"
              },
              "parent":
              {
                  "key": "TEST-1"
              },
              "summary": "Sub-task of TEST-1",
              "description": "Don't forget to do this too.",
              "issuetype":
              {
                  "id": "5"
              }
          }
      }

Result:

This tutorial was based on a tutorial from Atlassian that gives more info on REST API usage:

https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Create+Issue#JIRARESTAPIExample-CreateIssue-Exampleofcreatinganissueusingprojectkeysandfieldnames

Hope this helps?!

BenjiI
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.
May 19, 2014
{
    "expand": "projects",
    "projects": [
        {
            "self": "http://localhost:2990/jira/rest/api/2/project/10000",
            "id": "10000",
            "key": "TEST",
            "name": "test",
            "avatarUrls": {
                "16x16": "http://localhost:2990/jira/secure/projectavatar?size=xsmall&pid=10000&avatarId=10011",
                "24x24": "http://localhost:2990/jira/secure/projectavatar?size=small&pid=10000&avatarId=10011",
                "32x32": "http://localhost:2990/jira/secure/projectavatar?size=medium&pid=10000&avatarId=10011",
                "48x48": "http://localhost:2990/jira/secure/projectavatar?pid=10000&avatarId=10011"
            },
            "issuetypes": [
                ...
                {
                    "self": "http://localhost:2990/jira/rest/api/2/issuetype/5",
                    "id": "5",
                    "description": "The sub-task of the issue",
                    "iconUrl": "http://localhost:2990/jira/images/icons/issuetypes/subtask_alternate.png",
                    "name": "Sub-task",
                    "subtask": true
                },
                ...
            ]
        }
    ]
}

BenjiI
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.
May 19, 2014

NOTE: This REST call gives you an overview of all projects with their available issue types (and id):

http://localhost:2990/jira/rest/api/2/issue/createmeta

For instance the issuetype field in the JSON request bodies refer to an id from this REST API output (GET request):

Like Pär Skärmarker likes this
Raghuvamsi Uthpala May 20, 2014

Thanks a lot. POSTMAN plugin really helped me in tracing out the issue.

The issue is not taking Description field . Appreciate your help.

TAGS
AUG Leaders

Atlassian Community Events