Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a sub-tsk via scriptrunner gives an error even using the example given.

Lori Blatt
April 27, 2023
Here is the code in scriptrunner:

// Specify the key of the parent issue here
def parentKey = 'FN-29722'

// Get the parent issue type
def issueResp = get("/rest/api/2/issue/${parentKey}")
.asObject(Map)
assert issueResp.status == 200

// get the body of the parent issue type
def issue = issueResp.body as Map

// Get the issue types for the instance
def typeResp = get('/rest/api/2/issuetype')
.asObject(List)
assert typeResp.status == 200
def issueTypes = typeResp.body as List<Map>


// Here we set the basic subtask issue details
def summary = "DEV::BATCH - test" // The summary to use for
def issueType = "Sub-task" // The Sub Task Issue Type to Use

// Get the sub task issue type to use
def issueTypeId = issueTypes.find { it.subtask && it.name == issueType }?.id
assert issueTypeId : "No subtasks issue type found called '${issueType}'"

// Get the project to create the subtask in
def project = (issue.fields as Map).project

// Create the subtask
def resp = post("/rest/api/2/issue")
.header("Content-Type", "application/json")
.body(
fields: [
project: project,
issuetype: [
id: issueTypeId
],
parent: [
id: issue.id
],
summary: summary
])
.asObject(Map)

// Get and validate the newly created subtask
def subtask = resp.body
assert resp.status >= 200 && resp.status < 300 && subtask && subtask.key != null

// If the sub task created successfully return a success message along with its key
if (resp.status == 201) {
return 'Success - Sub Task Created with the key of ' + resp.body.key.toString()
} else {
return "${resp.status}: ${resp.body}"
}

 

 

Here is the error:

 

Serializing object into 'interface java.util.Map'
GET /rest/api/2/issue/FN-29722 asObject Request Duration: 659ms
Serializing object into 'interface java.util.List'
GET /rest/api/2/issuetype asObject Request Duration: 316ms
Serializing object into 'interface java.util.Map'
POST /rest/api/2/issue asObject Request Duration: 564ms
POST request to /rest/api/2/issue returned an error code: status: 400 - Bad Request
body: {errorMessages=[], errors={issuetype=The issue type selected is invalid., project=Issues with this Issue Type must be created in the same project as the parent.}}
Assertion failed: 

assert resp.status >= 200 && resp.status < 300 && subtask && subtask.key != null
       |    |      |      |  |    |      |     |          |
       |    400    true   |  |    400    false false      false
       |                  |  status: 400 - Bad Request
       |                  |  body: {errorMessages=[], errors={issuetype=The issue type selected is invalid., project=Issues with this Issue Type must be created in the same project as the parent.}}
       |                  false
       status: 400 - Bad Request
       body: {errorMessages=[], errors={issuetype=The issue type selected is invalid., project=Issues with this Issue Type must be created in the same project as the parent.}}

Class: com.adaptavist.sr.cloud.events.ConsoleScriptExecution, Config: [userTriggered:true]

 

1 answer

Suggest an answer

Log in or Sign up to answer
2 votes
Vitor Pelizza
September 18, 2017

Hi Ravi,

Here is the API docs: https://www.kanoah.com/docs/public-api/1.0/

And, the URL should be:

<your-jira-url>/rest/atm/1.0/

 For example, if you need to retrieve a test case, you can use:

<your-jira-url>/rest/atm/1.0/testcase/ABC-T123

 

Hope that helps :)

Regards,

Vitor 

Marius Bob
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!
August 23, 2018

I just found that on adaptavist rest api documentation but it doesn't work on my side. I get 404.

Our jira solution is cloud based. What's the base URL then? :)

 

Also they say something about Jira Context:

http://your-jira-host:port/your-jira-context/rest/atm/1.0/

What is that?

Like Vitor Pelizza likes this
berkaykirmizioglu
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!
November 8, 2018

This is really helped me, thank you.

Like Vitor Pelizza likes this
Vitor Pelizza
November 8, 2018

@berkaykirmizioglu, I'm glad that helped!

@Marius Bob, sorry I totally missed the notification for your comment, I suppose. We are still working on the API for the Cloud version, and the URL will be a bit different. Currently, we are on beta testing phase for the API.

Let me know if you want to get early access while still in beta, so I can give you a token? If that's the case, please raise a ticket on our support site: https://productsupport.adaptavist.com/servicedesk/customer/portal/33

 

Thanks.

Allen Jameson
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!
January 29, 2020

I came across this and was almost convinced there still wasn't a cloud version, but finally came across the cloud API reference, which I'm happy to say seems to work well!

https://docs.adaptavist.io/tm4j/cloud/api/v2/

Like Vitor Pelizza likes this
Vitor Pelizza
January 30, 2020

Yes, there is! And you can download the Swagger specs from the documentation to generate a client on the language you prefer if you want :)

Allen Jameson
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!
January 31, 2020

@Vitor Pelizza Thanks for your note.  I looked through the API and I have one or two questions:

- Can you get or set custom fields in test cases through the API? 

- Can you read history of a test case (change log) through the API? 

Vitor Pelizza
February 3, 2020

Hi Allen,

Custom fields are not yet supported; they are planned for later this year though.

Support for change history is not supported either, and there is no plan of introducing this.

Please feel free to open a feature request through our support site and we'll be happy to evaluate the features you need:

https://productsupport.adaptavist.com/servicedesk/customer/portal/33

Karina Santiago
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!
July 28, 2020

We are using Jira Server with TM4J add-on.

we can get the information about recently created test cases by rest api like https://{server:port}/rest/atm/1.0/testcase/search?query=projectKey = {"projectKey"} AND createdOn > "2020-06-17",

but we cannot track the recently updated test by making use of the field 'updatedOn' like

https://{server:port}/rest/atm/1.0/testcase/search?query=projectKey = {"projectKey"} AND updatedOn > "2020-06-17"

Are there the plan to support searching the test case by the field 'updatedOn'?

Hemendra Pratap Singh
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!
July 14, 2021

Hi. Is it possible to use the "https://{server:port}/rest/atm/1.0/testcase/search?query=projectKey = {"projectKey"} AND createdOn > "2020-06-17" API request for Jira Cloud also?

TAGS
AUG Leaders

Atlassian Community Events