A simple example code: function getCurrentUser(issueId)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.sal.api.user.UserManager
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.Response

import javax.ws.rs.core.MultivaluedMap

@BaseScript CustomEndpointDelegate delegate

getCurrentUser(httpMethod: "GET", groups: ["jira-software-users"]) { MultivaluedMap queryParams, body, HttpServletRequest request ->
    def userManager = ComponentAccessor.getOSGiComponentInstanceOfType(UserManager)
    def userProfile = userManager.getRemoteUser(request)
    def issueId = queryParams.getFirst("issueId") as String
    return Response.ok(new JsonBuilder([currentUser: userProfile?.username, issueId: issueId]).toString()).build();

Example query: /rest/scriptrunner/latest/custom/getCurrentUser?issueId=KEY-111

Example result:


By MrAddon


Posted by:.

One thought on “Example of Jira REST Endpoint with Groovy and using the user session

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s