How to bulk change the Project Admin for all projects in the same category using REST API
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
This article will cover the steps to define a new Project Admin for all projects in the same category. Currently, there is no easy way to do this via the Jira web UI.
Environment
This procedure was tested on Jira 8.5.1, but should be applicable to Jira 8.x and above.
Requirements
A Jira user with system administrator privileges.
Linux terminal or equivalent.
The following Linux binaries:
cURL - https://curl.haxx.se/
bash (optional) - https://www.gnu.org/software/bash/
Solution
A shell script can be used to retrieve all projects under a single category using the Jira REST API and then update them with the new Project Admin user. An example script is provided below as a sample for reference.
Custom shell scripting is outside the scope of Atlassian support. This page and its example script are provided for your information only.
We recommend that you validate any shell scripts in a test environment before running them in production.
Example script: changing the project admin
Shell Script
1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/sh
typeset _BASE_URL="<JIRA_BASE_URL>"
typeset _CREDENTIALS="<USER>:<PASSWORD>"
# Retrieving the projects under category XYZ with category ID 10000
typeset _CATEGORY_ID=10000
typeset _PROJECT_LIST=$(curl -s -u $_CREDENTIALS $_BASE_URL/rest/api/2/project | jq '.[] | select(.projectCategory.id=="'$_CATEGORY_ID'")' | jq -r ."key")
# Updating the projects with the new admin
typeset _NEW_ADMIN="\"<userid>\""
echo $_NEW_ADMIN
for _PROJECT in $_PROJECT_LIST;do
curl -D- -u ${_CREDENTIALS} -X POST --data '{ "user": ['$_NEW_ADMIN'] }' -H "Content-Type: application/json" $_BASE_URL/rest/api/2/project/$_PROJECT/role/10002
done
If you're not sure what the correct category ID is, you can obtain the list of project categories, including their names and IDs, using the REST API:
Retrieving project categories
1
curl -s -u <USER>:<PASSWORD> <JIRA_BASE_URL>/rest/api/2/projectCategory | jq .
After running the shell script, the changes can be validated using the REST API:
Validating the changes
1
curl -s -u <USER>:<PASSWORD> <JIRA_BASE_URL>/rest/api/2/project/<ONE_PROJECT_KEY> | jq .lead.name
Was this helpful?