Forums

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

Hi how can I access the current issue properties in Rest end points

Pradeep A
Contributor
July 8, 2021

Hi Im working with Script fragments and rest endpoints to run a script. What I need is to access the issue properties so that I could display the Issue details when I click the web Item.

 

Basically I need to know how to access issue object in a rest endpoint

 

Thanks

1 answer

0 votes
PD 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.
July 12, 2021

You must transmit the issue that you want to work with via the http request and your endpoint must be ready to accept this information in one of 2 or 3 ways (there may be others).

If your Endpoint is a GET, then you can pass the issue via the request query parameter or request path. If it's a PUT or POST, then it could be either in the request query parameter, request path or payload data.

For example, if you call the rest endpoint from an issue context in a web item fragment, you can make the URL something like this:

/rest/scriptrunner/latest/custom/yourEndPoint?issueKey=${issue.key}

Then in your rest Endpoint:

yourEndPoint(httpMethp:'GET', groups:['jira-users']){MultivaluedMap queryParams ->
def issueKey = queryParams.getFirst('issueKey')
if(!issueKey){
return Response.serverError().entity([error:'You must specify issueKey in request query parameter']).build()
}
def issue=  ComponentAccessor.issueManager.getIssueObject(issueKey)
/* do stuff with issue object */
}

Suggest an answer

Log in or Sign up to answer