Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Create subtask for Jira ticket based on Issue name or description using REST API-SOLVED

Dragan Vucanovic February 22, 2018

Hello, i'm new to Jira.

Is it possible to create following scenario:

For JIRA ticket created with subject:Check o365 license

- description: No spare licenses unused.

- create sub tasks for the parent ticket using REST API,

I managed to find a code for adding a comment to ticket by TICKET ID, is it possible to search by subject or description

 

curl -D- -dvucanovic:pass -H "Content-Type: application/json" -X POST -d '{ "body": "Test comment" }' https://jira.corp.hentsu.com/rest/api/2/issue/TECH-513/comment

 

 

2 answers

1 accepted

2 votes
Answer accepted
Dragan Vucanovic February 23, 2018

Uh !, you were right Laurens, i wasted whole day on this, Atlassian  documentation needs serious update for JIRA Service Desk 3.4.had to add customfield_10107,what's that  ??

Is this new feature ?

anyway, i just created post if anyone needs this:

https://geekdudes.wordpress.com/2018/02/23/create-jira-subtask-using-rest-api/

Laurens Coppens
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 23, 2018

Glad i could help!

0 votes
Laurens Coppens
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 22, 2018

I would advise to use the automation plugin to do this, instead of rest api.

Dragan Vucanovic February 22, 2018

Thanks, but i'm asked to do it using REST API,

Laurens Coppens
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 22, 2018

Dragan,

Then i think this is what you need: https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-Create-Subtask-using-Rest-API/qaq-p/508166

The code to create a subtask.

But you will need to find a way to call the script to create the subtask based on the subject.

Thats why i think automation is better, you can just add an event "issue created" where subject contains "Check license" then create sub task.

Dragan Vucanovic February 22, 2018

Thanks a lot Laurens !, can you point me to links or examples for automation plugins, i'm totally noob for this :)

Laurens Coppens
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 22, 2018
Dragan Vucanovic February 22, 2018

I see it's chargable, now i know why i'm asked to find free solution :)

I'm still searching for REST API option.

 

Thanks !

Laurens Coppens
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 22, 2018

Dragan,

Scripting (hour cost) is also quite expensive :-)

So unless you got a high user count, i think it will still be the cheapest option.

But in case you still want rest api is suggest you to check out the first link.

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"
        }
    }
}

 

And then you just need to find the parent key based on a search for description and put in in the rest api call.

Laurens Coppens
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 22, 2018

If you use cloud and <300 rule executions you can use the free version of automation: https://marketplace.atlassian.com/plugins/com.codebarrel.addons.automation.lite/cloud/overview

Dragan Vucanovic February 22, 2018

Thanks again, meanwhile i found values for Issue subject and comment:

description and summary, but when composing a query for Technology and summary, for examples i got error and results for all tickets within project

 

 curl -D- -u user:password -X GET -H "Content-Type: application/json" https://jira.corp.company.com/rest/api/2/search?jql=project="Technology" and summary="Check o365 license"

i got error

 

curl: (6) Could not resolve host: summary=Check o365 license Unknown error

Laurens Coppens
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 22, 2018

not sure but I think you need to escape the quotes for project and summary

Dragan Vucanovic February 22, 2018

wow, you were right Laurens:

 

curl -D- -u user:password -X GET -H "Content-Type: application/json" https://jira.corp.comapny.com/rest/api/2/search?jql=project='"Technology"+AND+summary~"Check%20the%20o365%20License"'

now, how to extract key and pass it to code in firs link ?

Laurens Coppens
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 22, 2018

i think you will need to write a powershell/bash/perl/... script to process the requests.

Thats why i believe automation is the way to go.

Dragan Vucanovic February 22, 2018

okay, i use this bash to create subtask:

 

curl -D- -u user:pass -X POST --data {"fields":{"project":{"key":"TECH"},"parent":{"key":"TECH-456"},"summary":"Sub-task of TECH-456","description": "Don't forget to do this too.","issuetype":{"id":"10001"}}} -H "Content-Type:application/json" https://jira.company.com/rest/api/2/issue
 


JSON file is in attachment
  curl: (3) [globbing] unmatched close brace/bracket at pos 50
HTTP/1.1 400
Date: Thu, 22 Feb 2018 19:01:53 GMT
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: nginx/1.10.2
X-AREQUESTID: 1141x104118x1
X-ASEN: SEN-6467483
Set-Cookie: JSESSIONID=26812A29DDF33852DBF21FFCED126F82;path=/;Secure;HttpOnly
X-Seraph-LoginReason: OK
Set-Cookie: atlassian.xsrf.token=B8QW-16KW-V2F7-JHDF|a6862b0311b0f2eab0ff6151de67eeb64283de9f|lin;path=/;Secure
X-ASESSIONID: j1ez3l
Cache-Control: no-cache, no-store, no-transform
X-Content-Type-Options: nosniff {"errorMessages":["Unexpected character ('f' (code 102)): was expecting double-quote to start field name\n at [Source: org.apache.catalina.connector.CoyoteInputStream@260ee49e; line: 1, column: 3]"]}

Dragan Vucanovic February 22, 2018

curl -D- -u user:pass -X POST --data {"fields":{"project":{"key":"TECH"},"parent":{"key":"TECH-456"},"summary":"Sub-task of TECH-456","description": "Don't forget to do this too.","issuetype":{"id":"10001"}}} -H "Content-Type:application/json" https://jira.company.com/rest/api/2/issue

 

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events