Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Can I change the parent field of sub-task in Jira via REST API ?
I tried the command:
/usr/bin/curl -u admin:zubur1 -X POST -H Content-Type:application/json 'http://<my-jira>:<port>/rest/api/2/issue/<issue_key>' --data @@@jsonfile.json
jsonfile content:
{
"fields":
{
"parent":
{
"key": "<issue_key>",
"id": "<issue_id>"
}
}
}
I got HTTP response code 405
Thanks,
Yakir Giladi
If you have ScriptRunner you can change the parent like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.pico.ComponentManager
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Issue childIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("DEMO-69")
Issue parentIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("DEMO-9")
ComponentAccessor.getSubTaskManager().changeParent(childIssue, parentIssue, user)
Actions of this script are not visible in the history of the issue's changes =(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @scott_boisvert !
Is this solution could be performed by using REST API?
With kind regards
Viacheslav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@IT Accounts You can update the script to add an entry to the history log if you want.
@Slava Starovoitov I do not believe there is a built in API call from Atlassian. However, using ScriptRunner you could create a REST EndPoint that uses this script, and then yes, you could do this with REST API.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Scott Boisvert thanks for the quick reply!
bq. However, using ScriptRunner you could create a REST EndPoint that uses this script, and then yes, you could do this with REST API.
@Scott Boisvert Yes, I mean using SR. Could you give a little information about how to create a REST EndPoint? We need to do it in SR settings or you mean our self application?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Viacheslav Starovoytov Adapavist has some good documentation on how to create a REST Endpoint: https://scriptrunner.adaptavist.com/latest/jira/rest-endpoints.html
You need to be an administrator to create one though. You would need to pull in your parameters and assign them to a variable for example the issue key(s).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Scott Boisvert thank you very much, with your help I have managed with changing parent issue (y)
Additionally I put in the script this line in the code:
issueManager.updateIssue(user,mIssue,EventDispatchOption.ISSUE_UPDATED, false)
to update the history (where mIssue is childissue), but I do not get any update. Could you help with this last thing?
With kind regards
Viacheslav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Right after
ComponentAccessor.getSubTaskManager().changeParent(childIssue, parentIssue, user)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Slava Starovoitov if your using this in post function, make sure it is before the standard: Update change history for an issue and store the issue in the database.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Scott Boisvert Hi! No, it is not a post-function. As you advised we raised the self endpoint. Is it appropriate code for this?
With kind regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Viacheslav Starovoytov The line you added from what I understand should update the history, but looks like your referencing a different issue (mIssue) where you have childIssue and parentIssue variables in use.
See this post: https://community.atlassian.com/t5/Jira-questions/Why-doesn-t-Script-Listener-write-to-Issue-History/qaq-p/1174927
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Scott Boisvert @Scott Boisvert firstly I had this
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import javax.servlet.http.HttpServletRequest
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.event.type.EventDispatchOption
@BaseScript CustomEndpointDelegate delegate
def issueManager = ComponentAccessor.issueManager
changeParent(
httpMethod: "POST", groups: ["jira-administrators","jira-robots"]
) { MultivaluedMap queryParams, String body, HttpServletRequest request ->
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Issue childIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("TEST-361")
Issue parentIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("TEST-531")
ComponentAccessor.getSubTaskManager().changeParent(childIssue, parentIssue, user)
issueManager.updateIssue(user,childIssue,EventDispatchOption.ISSUE_UPDATED, true)
return Response.ok(new JsonBuilder([abc: 42]).toString()).build()
}
And then I changed it to this
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import javax.servlet.http.HttpServletRequest
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue;
@BaseScript CustomEndpointDelegate delegate
def issueManager = ComponentAccessor.issueManager
def MutableIssue mIssue = issueManager.getIssueByCurrentKey("TEST-361")
changeParent(
httpMethod: "POST", groups: ["jira-administrators","jira-robots"]
) { MultivaluedMap queryParams, String body, HttpServletRequest request ->
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Issue childIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("TEST-361")
Issue parentIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("TEST-531")
ComponentAccessor.getSubTaskManager().changeParent(childIssue, parentIssue, user)
issueManager.updateIssue(user,mIssue,EventDispatchOption.ISSUE_UPDATED, true)
return Response.ok(new JsonBuilder([abc: 42]).toString()).build()
}
cause I found some ticket related to this problem and there was this advise.
But both variants do not have impact on history. What may be wrong here?
With kind regards
Viacheslav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Viacheslav Starovoytov Based on my limited knowledge that should work, but you may need to use ChangeHistoryItem.Builder: https://docs.atlassian.com/software/jira/docs/api/7.0.6/com/atlassian/jira/issue/changehistory/ChangeHistoryItem.Builder.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Scott Boisvert !
It seems that ChangeHistoryItem.Builder is for reading information from history, is not it?
With kind regards
Slava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Viacheslav Starovoytov nope, reading history is a different class. ChangeHistoryItem.Builder should be the correct class to "Build" a history item. I've not used it before (so i dont have any direction to give you on how to use the class), but that "Builder" usually means you're creating an instance of that class so you can post it to the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Scott Boisvert ok. I was searching by "ChangeHistoryItem.Builder", and found only getting a history examples.
In any case huge thanks!
Will try to do it with myself and may be with someone else)
Good night!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Andy Heinzer It's been almost 4 years now and still, this API is not available in the server version. An API was created for the Cloud Version of the JIRA last year but no love for JRASERVER-68763. It has gathered enough interest. Can this be picked up now, please?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately, not all fields of an issue can be edited in this way. In this case, you can't just change the parent ID field for a subtask. Even when in the web front end of Jira, you can't just edit that field on this issue. This is because this is a system field that is specific to that issue type (subtasks are special snowflakes in this regard). Outside the REST API, the only way to change a subtask to be under a new parent issue is to call the move function in Jira, and in turn move the issue to a new parent.
The problem as I see it is the REST API's current inability to move issues. There is an existing feature request for this in https://jira.atlassian.com/browse/JRASERVER-61359
Should this someday be implemented in Jira, then I would expect that you could then move subtasks via a REST call.
I have not found any other work-arounds for this problem, but you are not alone here, this question has been asked a number of times before:
https://community.atlassian.com/t5/Answers-Developer-Questions/REST-API-move-sub-task/qaq-p/510350
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Varrun SS
The pair of feature requests in JRASERVER-61359 and JRASERVER-68763 are still accurate. Unfortunately, even in the current versions of Jira Server (8.1.0 today), you cannot move an issue or change a subtask's parent via the REST API.
I would recommend watching these two tickets. Should this feature come to Jira Server, I would expect these to be updated to reflect which version of Jira would gain this feature.
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's been almost 4 years now and still, this API is not available in the server version. An API was created for the Cloud Version of the JIRA last year but no love for JRASERVER-68763. It has gathered enough interest. Can this be picked up now, please? @Andy Heinzer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.