Hello Community,
I am having a weird issue with Jira Rest Endpoints.
I want to grab an issue from Jira via Rest Endpoint utilizing IssueManager Object.
I have done this in Behaviours and in Custom Listeners and I never had a problem retrieving the issue by its key or id.
When I try the same code in Rest EndPoint I am returned null or a bunch of errors, such as:
Script endpoint failed on method: GET myEndPoint
java.lang.StackOverflowError
and
{"message":null,"stack-trace":"java.lang.StackOverflowError\n","status-code":"INTERNAL_SERVER_ERROR"}Below is my code:
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.jira.user.util.UserManager
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.CustomFieldManager;
@BaseScript CustomEndpointDelegate delegate
myEndPoint(httpMethod: "GET") { MultivaluedMap queryParams, String body ->
def issueKey = "HTP-366"
def issueManager = ComponentAccessor.getIssueManager()
//Grab issue we are modifying/transitioning
MutableIssue story = issueManager.getIssueObject("HTP-366");
return Response.ok(new JsonBuilder([storyd: issueManager.getIssueCount(), story: results]).toString()).build();
}
From my understanding of IssueManager and ComponentManager, this is how one grabs Issues.
The weird thing is that I can grab IssueManager and I cant utilize all of its functions such as .getIssueCount() and it returns me the correct number. But when I add the key of an issue that exists in my Jira such as HTP-366, I either get "null" or the errors shown above. Also, I can use UserManager to grab any user by their respective userKey and it returns me the User Object.
Furthermore, I found a similar question to mine in the community but it was never truly solved:
https://community.atlassian.com/t5/Adaptavist-questions/Issue-Manager-getIssueObject-oddity/qaq-p/458910
I appreciate any help on this!
-Roberto