You can now vote for scripts to help people know if they're useful or not. Login or create an account to vote!


Use the REST endpoint to get the organization's details


When the organization's details in a Service Desk are required, a REST endpoint request is made to invoke the details.


This sample script lists all the organization names and IDs that have been configured for the Service Desk. Only the organization's name and ID are extracted. The JSON response returned from the REST request can then be invoked as required. For example, you could use Behaviour to perform validation on the organization's name format.


  • Jira Service Desk Jira Service Desk (4.0 - 4.20)
  • ScriptRunner for Jira ScriptRunner for Jira (6.41.0)
import com.atlassian.jira.component.ComponentAccessor import import groovy.json.JsonBuilder import groovy.transform.BaseScript import import javax.servlet.http.HttpServletRequest import import @BaseScript CustomEndpointDelegate delegate getOrganizations { MultivaluedMap queryParams, body, HttpServletRequest request -> def serviceDeskId = queryParams.getFirst('serviceDeskId') def applicationProperties = ComponentAccessor.applicationProperties final def baseUrl = applicationProperties.getString('jira.baseurl') final def username = 'admin' final def password = 'q' final def headers = ['Authorization': "Basic ${"${username}:${password}".bytes.encodeBase64()}", 'X-ExperimentalApi': 'opt-in', 'Accept': 'application/json'] as Map def http = new RESTClient(baseUrl) http.setHeaders(headers) def resp = http.get(path: "/rest/servicedeskapi/servicedesk/${serviceDeskId}/organization") if (resp.status != 200) { log.warn 'Commander did not respond with 200 for retrieving project list' } def issueJson = as Map def values = issueJson.get('values') def idList = values['id'] def nameList = values['name'] def result = [idList, nameList].transpose().collectEntries { [it[0], it[1]] } Response.ok(new JsonBuilder(result).toPrettyString()).build() }
Discovered an issue? Report it here