Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need a groovy script to extract all users in all orgs for a JSM Project (Jira 10.3)

Normann P_ Nielsen _Netic_
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 Champions.
December 22, 2025

Tried a lot of my old code and what ChatGTP and Gemini offers.

In general the latter two messes around regarding the API's that seems to have changed quite a lot around "OrganizationsQuery" ...

Does anyone have a working script?

2 answers

0 votes
Marc -Devoteam-
Community Champion
December 23, 2025

Hi @Normann P_ Nielsen _Netic_ 

You can use the API endpoint provided for DC, https://developer.atlassian.com/server/jira-servicedesk/rest/v1103/api-group-organization/#api-group-organization 

Or a python script, e.g.:

import requests

BASE_URL = "https://your-jira-instance.com"
AUTH = ('username', 'password_or_token')
HEADERS = {"Accept": "application/json"}

# 1. Fetch Organizations
orgs_resp = requests.get(f"{BASE_URL}/rest/servicedeskapi/organization", auth=AUTH, headers=HEADERS)
organizations = orgs_resp.json().get('values', [])

for org in organizations:
print(f"Organization: {org['name']} (ID: {org['id']})")

# 2. Fetch Users for this Org
users_resp = requests.get(f"{BASE_URL}/rest/servicedeskapi/organization/{org['id']}/user", auth=AUTH, headers=HEADERS)
users = users_resp.json().get('values', [])

for user in users:
print(f" - User: {user['displayName']} ({user['emailAddress']})")

Or query the database:

SELECT
org.NAME AS "Organization Name",
u.lower_user_name AS "Username",
u.display_name AS "Display Name"
FROM "AO_54307E_ORGANIZATION" org
JOIN "AO_54307E_ORGANIZATION_MEMBER" mem ON org.ID = mem.ORGANIZATION_ID
JOIN "app_user" au ON mem.USER_KEY = au.user_key
JOIN "cwd_user" u ON au.lower_user_name = u.lower_user_name
ORDER BY org.NAME;

Or Groovy, but can't test this:

import com.atlassian.servicedesk.api.organization.OrganizationService
import com.atlassian.servicedesk.api.organization.UsersInOrganizationQuery
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean

@WithPlugin("com.atlassian.servicedesk")
def orgService = com.atlassian.sal.api.component.ComponentLocator.getComponent(OrganizationService)
def currentUser = com.atlassian.jira.component.ComponentAccessor.jiraAuthenticationContext.loggedInUser

// Define query for all organizations
def orgQuery = orgService.newOrganizationsQueryBuilder().build()
def orgs = orgService.getOrganizations(currentUser, orgQuery).getResults()

orgs.each { org ->
log.info "Organization: ${org.name}"
def userQuery = orgService.newUsersInOrganizationQueryBuilder()
.organization(org)
.build()

def users = orgService.getUsersInOrganization(currentUser, userQuery).getResults()
users.each { user ->
log.info " --> ${user.displayName}"
}
}

Normann P_ Nielsen _Netic_
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 Champions.
December 23, 2025

That was awesome @Marc -Devoteam- but actually left with a derived issue:

A Service Desk customer placed with no Org and no role - is still a Service Desk Customer:

Screenshot 2025-12-23 at 10.47.11.png

So I have Project Id and Service Desk Id - but no Org Id ..

Marc -Devoteam-
Community Champion
December 23, 2025

Hi @Normann P_ Nielsen _Netic_ 

SD customers, not linked to an Org don't has and Org ID set.

So this why you will not see na ORG ID at customers not linked to an Org.

Normann P_ Nielsen _Netic_
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 Champions.
December 23, 2025

Yeah - but that kind of leaves my "Access Management" reporting going only half way...

Normann P_ Nielsen _Netic_
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 Champions.
December 23, 2025
Like Marc -Devoteam- likes this
0 votes
Mohamed Benziane
Community Champion
December 23, 2025

Hi,

You can use this api to get all users in a JSM organization: 

The Jira Service Management Cloud REST API

Marc -Devoteam-
Community Champion
December 23, 2025

Hi @Mohamed Benziane 

The tags on the question indicate @Normann P_ Nielsen _Netic_ is running Jira on DC, so the provided cloud api option will not fulfil his need.

Like Mohamed Benziane likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events