JIRA REST API: How to get nested groups

George Lewe (LSY)
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.
June 9, 2016

Hi there,

I am able to read all groups from JIRA via the REST API.

Is there any way that I can also read the nested groups for each via REST?

Best regards,
George

1 answer

3 votes
Boris Georgiev _Appfire_
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.
June 9, 2016

There's no REST API for this, but you can easily implement your own REST endpoint with Script Runner  for example. Then you can all it at rest/scriptrunner/1.0/custom/childgroups/?group=parent assuming your group that you want to examine is called parent.

here's the code:

import com.atlassian.jira.bc.group.GroupService;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserUtil;
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
childgroups(httpMethod: "GET", groups: ["jira-users"]) { MultivaluedMap queryParams, String body ->
	def name = queryParams.get("group")
	def uu = ComponentAccessor.getComponent(UserUtil.class)
	def group = uu.getGroup(name)
	def gs = ComponentAccessor.getComponent(GroupService)
	
	return Response.ok(new JsonBuilder(gs.getChildGroupNames(group)).toString()).build();
}

Suggest an answer

Log in or Sign up to answer