Rest EndPoint - IssueManager not working, returning NULL or a bunch of errors

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

1 answer

This widget could not be displayed.

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 

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

165 views 2 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you