How to add User Roles in Orchestrator using API?
Issue Description
To edit user roles using the UiPath Orchestrator API, you need to interact with the Orchestrator API endpoints designed for managing users and roles. Here’s a step-by-step guide to help you with the process.
Prerequisites
- Access to UiPath Orchestrator: Ensure you have administrative access to UiPath Orchestrator.
- API Access: Make sure you have the API access credentials (Tenant name, Client ID, and Client Secret).
Step 1: Obtain an OAuth Token
To interact with the Orchestrator API, you need to authenticate and obtain an OAuth token.
Step 2: Retrieve User ID
To edit roles, you first need the ID of the user whose roles you want to modify.
Request: GET https:///odata/Users?$filter=UserName eq ''
Authorization: Bearer
Response:
{
"value": [
{"Id": ,
"UserName": "",
"Email": ""}]
}
Step 3: Retrieve Role IDs
Next, you need to get the IDs of the roles you want to assign or remove.
Request: GET https:///odata/Roles
Authorization: Bearer
Response:
{
"value":
[
{"Id": ,
"Name": ""}
]
}
Step 4: Assign or Update User Roles
To update the roles for a user, you need to perform a PATCH request to modify the user’s roles.
Request: PUT https:///odata/Users()
Authorization: Bearer
Content-Type: application/json
{
"Roles": [
{
"Id": }]
}
In this PUT request:
- Replace with the ID of the user you retrieved earlier.
- Replace with the ID of the role(s) you want to assign to the user.
Step 5: Confirm Changes
Verify that the user roles have been updated by querying the user details again or checking the Orchestrator UI.
Request: GET https:///odata/Users()
Authorization: Bearer
Response:
{"Id": ,
"UserName": "",
"Roles": [
{"Id": ,
"Name": ""}
]
}
Summary
- Authenticate to get an access token.
- Retrieve user and role IDs.
- Update user roles with a PATCH request.
- Verify the changes.
Always ensure you handle API credentials and sensitive information securely. If you encounter any issues, checking the UiPath Orchestrator API documentation and logs can help troubleshoot.