Custom Endpoint help for JIRA API

Joel Batac May 9, 2023

HI, This is my first time creating a custom rest endpoint. I tried to research but I can't find any. So basically i jsut want to call a jira api and display the output. Below is the code

 

getWorkflowNames(
httpMethod: "GET", groups: ["jira-users"]
) { MultivaluedMap queryParams, String body, HttpServletRequest request ->
     def extraPath = getAdditionalPath(request)
    if (extraPath == "" || extraPath == "/") {
        return Response.ok(new JsonBuilder(["Enter a project key. Ex: " +jiraurl+ "/rest/scriptrunner/latest/custom/getWorkflowNames/PROJ"]).toString()).build()
    } else {
        def projectKey = extraPath.split('/')[1]
        def String ProjKey = queryParams[projectKey];
        return Response.ok(new JsonBuilder(['I need to get the output of this line but how? : ' +jiraurl+'/rest/api/latest/project/'+projectKey+'/workflowscheme']).toString()).build()
    }
}
I'm trying to look for something like 
return(new URI (jiraurl+'/rest/api/latest/project/'+projectKey+'/workflowscheme')).build()

1 answer

0 votes
Ken McClean
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 9, 2023

I wrote a little bit on accessing REST resources using ScriptRunner for both Jira Server and Jira Cloud.  Maybe something in there could be of use to you.

https://www.kennethmcclean.com/blog/scriptrunner-foundations-accessing-jira-rest-api-using-groovy/

Full credit as always to @Peter-Dave Sheehan for writing the original post that helped me figure it out.

Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 9, 2023

Getting name-dropped in a blog! Am I a celebrity now?

You might appreciate simplifying this even more by encapsulating what you call the "framework" in a simple class.

Then you can just call it like this:

import jiraserver.scriptrunner.utils.SRRestUtil
def srRestUtil = new SRRestUtil()
srRestUtil.makeRequest('GET', srRestUtil.baseUrl + '/rest/api/<version>/<endpoint>', [mapKey:mapValue])

I've shared my version of such a class here: https://bitbucket.org/peter_dave_sheehan/groovy/src/master/jiraserver/scriptrunner/utils/

Like Ken McClean likes this

Suggest an answer

Log in or Sign up to answer