Errors with scriprunner code rest api

Hi guys,
I have this code which eventually should be in a scriptrunner listener. Right now I am testing it in the console.
For some reason although I manage to get the keys for the issues I cannot perform the transition or change the status. Can someone advise where is the problem?

The error messages I receive are:

When I try the put transition request I get:

POST /rest/api/2/issue/AKD-469/transitions asObject Request Duration: 162ms

POST request to /rest/api/2/issue/AKD-469/transitions returned an error code: status: 400 - Bad Request

body: {errorMessages=[Can't move (AKD-469). You might not have permission, or the issue is missing required information. If you keep having this problem, contact your Jira Administrator.], errors={}}

When I try the put status request I get:

PUT /rest/api/2/issue/AKD-469?overrideScreenSecurity=true asString Request Duration: 984ms

PUT request to /rest/api/2/issue/AKD-469?overrideScreenSecurity=true returned an error code: status: 403 - Forbidden

body: {"errorMessages":["Connect app users with a\”admin\" permission and Forge app users with the \"manage:jira-configuration\" scope can override screen security."],"errors":{}}

The complete code is here and (it contains both the put and post requests but I comment one of them each time so only the other is executed.)

def issueKey = 'AKD-452' //issue.key
def newTransitionId = '721'
def newStatus = 'On Staging'
def newStatusID = 10005
def result = get('/rest/api/2/issue/' + issueKey)
        .header('Content-Type', 'application/json')

// Find the linked issues
def linkedIssuesKey = result.body.fields.issuelinks.inwardIssue.key
def length = linkedIssuesKey.size()
for (i in 0..<length) {
    def submit = put("/rest/api/2/issue/${linkedIssuesKey[i]}")
            .queryString("overrideScreenSecurity", Boolean.TRUE)
            .header('Content-Type', 'application/json')
    return submit
    // def transitionIssue = post("/rest/api/2/issue/${linkedIssuesKey[i]}/transitions")
    //         .header("Content-Type", "application/json")
    //         .body([transition: [id: newTransitionId]])
    //         .asObject(Map)
    // Log out the issues transitioned or which failed to be transitioned"Transition ${newTransitionId} performed for the ${linkedIssuesKey[i]} issue")
    // return ['Issue:', ${linkedIssuesKey[i]}, 'was moved to On "Staging"'];

Welcome to the Atlassian Developer Community, @HadasHamerovv !

This request requires specific permissions. Based on the error 400 you got, it is possible that the user does not have permission to transition the issue. If it is not permission related, you might also want to double check the allowable transitions for the user by calling Get Transitions - by doing so you’ll have more confidence that the user can indeed transition the issue, and you’ll also get the correct transition ID.

The error 403 you got means the user does not have the necessary permissions. For more information on the errors, feel free to check this doc.


Thanks Ian,
The user has permissions. It was something in the code syntax. After modifying the way the json body is structured it is working now (I think also that is rest/api/3 and not 2).

I appreciate very much you taking the time to look at it.