Adding a User to Project Roles via Jira 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 explains how to use the Jira REST API to add users to project roles, such as the "Administrators" role, by sending a PUT request to the appropriate endpoint. It includes step-by-step instructions and example commands for configuring the REST API using a Personal Access Token (PAT).
Environment
Jira version 5.0 and above
Cause
Administrators may need to bulk-assign users to project roles across multiple projects or automate role assignments for consistency and ease of management. Doing this manually can be time-consuming.
Solution
Follow these steps to add a user to a project role via the Jira REST API:
Generate a Personal Access Token (PAT) for authentication.
More information on creating a PAT can be found here
Identify the project and role IDs:
Use the API endpoint /rest/api/2/project to retrieve the project list and select the relevant project ID.
Use the project role endpoint to identify the role ID: /rest/api/2/project/{projectId}/role.
Prepare a a PUT request:
Use the following cURL command to add a user to the specified role:
PUT Request to add the user to the specified role
1 2 3 4 5 6 7 8 9
curl -X PUT \ -H "Authorization: Bearer <PAT_TOKEN>" \ -H "Content-Type: application/json" \ -d '{ "categorisedActors": { "atlassian-user-role-actor": ["username"] } }' \ <JIRA_BASE_URL>/rest/api/2/project/{PROJECT_ID}/role/{ROLE_ID}
Test and verify the role assignment:
The user will now have the role assigned in the specified project. You can repeat this for other projects by changing the project ID in the API endpoint.
Was this helpful?