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?
Hi,
You can use this api to get all users in a JSM organization: The Jira Service Management Cloud REST API
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.
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 Organizationsorgs_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 Orgusers_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" orgJOIN "AO_54307E_ORGANIZATION_MEMBER" mem ON org.ID = mem.ORGANIZATION_IDJOIN "app_user" au ON mem.USER_KEY = au.user_keyJOIN "cwd_user" u ON au.lower_user_name = u.lower_user_nameORDER BY org.NAME;
Or Groovy, but can't test this:
import com.atlassian.servicedesk.api.organization.OrganizationServiceimport com.atlassian.servicedesk.api.organization.UsersInOrganizationQueryimport com.onresolve.scriptrunner.runner.customisers.WithPluginimport 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 organizationsdef 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}"}}
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:
So I have Project Id and Service Desk Id - but no Org Id ..
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.
Yeah - but that kind of leaves my "Access Management" reporting going only half way...
It looks like you're new here. Sign in or register to get started.