Bulk Role Modify Role Owner

Hello Community,

I need to modify the role owner of several roles at once ( 800)

What is the best way to do it please ? Any documentation on this subject would be much appreciated too,

Thank you,

the best way is you can use script that will apply on bulk, may be you can use python script

1 Like

Do you have any example please?

Hello Torry,

I am sending you my script example that I did before.

modifyRole.py (3.4 KB)

You just need to adapt it with your role configuration.

You can use as input a CSV file to store all your information regarding your 800 roles.

I hope it will help you :smiley:

I used following for APs you just change role API for the following, and use update offset 0, 250, 500 etc until all roles looped

import requests
import json

accessToken = ''
org = ''

getAccessProfileUrl = f'https://{org}.api.identitynow.com/beta/access-profiles?limit=250&offset=200'
accessProfiles = requests.request("GET", getAccessProfileUrl, headers={ 'Authorization': 'Bearer ' + accessToken }).json()
ownerId = ''
ownerName = ''

patchBody = json.dumps([
  {
    "op": "replace",
    "path": "/owner",
    "value": {
      "type": "IDENTITY",
      "id": ownerId,
      "name": ownerName
    }
  }
])

for accessProfile in accessProfiles:
        z=accessProfile["id"]
        updateUrl = 'https://org.api.identitynow.com/beta/access-profiles/'+z
        headers = {
                'Content-Type': 'application/json-patch+json',
                'Authorization': 'Bearer ' + accessToken
        }
        updatedAccessProfile = requests.request("PATCH", updateUrl, headers=headers, data=patchBody).json()
        print(f'Changed owner for {updatedAccessProfile["name"]} to {ownerName}')

print('Finished')
1 Like

Another option can be : VSCODE plugin, by exporting in csv, update manually owner and import.

2 Likes

@torry_salamat ,
There are multiple ways this can be achieved.

  1. Writing a Script to update roles using API calls. Script should fetch all the roles in Json format in a folder. Further, script should read each role json, one by one, and change the json file e.g. replace the role owner id value, and then create the updated Json in another folder. then in the last part, Script should read all the modified jsons, one by one, take the json content as body for PATCH API call to update all the roles.
  2. Export all the Roles in JSON format using VSCode plugin. Modify roles in csv using csv functions such as find and replace.
    Then Import these roles using VSCode import function.
    Upward arrow is for Export, and Downward arrow is for importing using csv.

image

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.