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:
I appreciate any help on this!
-Roberto
Hi Roberto,
Can I ask you, if you want to get just the issue, why you do not use the Jira Rest API and instead you are trying to reinvent the wheel ?
Maybe if you could give a use case ?
Regards, Thanos
@Thanos Batagiannis _Adaptavist_,
That was probably a bad example.
So thats part 1 of the EndPoint, it has about 80 more lines of code.
The rest of the code works fine so I decided to take it out of question to avoid any unnecessary confusion.
What I am doing is I am getting issueKey as an extra path in EndPoint URL. I send that to IssueManager, get the issue this EndPoint is referencing and after that I use that Issue Object to do some computation based on certain conditions.
For somereason the IssueManager part isnt working, as I mentioned above. I get NULL and I saw someone elses post that had run into this issue before.
-Roberto
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.