I know there is an API where you can update a source owner using the PATCH /beta/sources/{id}. Is there a way to update multiple source owners at one time?
Hi @RArroyo,
Yes, you can update multiple source owners in one go, but it will require you to write a script that will loop over a list of sources and update each to the new owner. The following Python script will get you started. It finds all sources that are of type “None Employee” and changes the owner of each to the same owner. This can be modified to suit your needs. You will probably need to run the following command to install the requests
library if you don’t already have it.
python3 -m pip install requests
You will need to provide your own org
, accessToken
, ownerId
, and ownerName
to execute this script.
import requests
import json
accessToken = ''
org = ''
getSourcesUrl = f'https://{org}.api.identitynow.com/v3/sources?filters=type eq \"Non-Employee\"'
sources = requests.request("GET", getSourcesUrl, headers={ 'Authorization': 'Bearer ' + accessToken }).json()
ownerId = ''
ownerName = ''
patchBody = json.dumps([
{
"op": "replace",
"path": "/owner",
"value": {
"type": "IDENTITY",
"id": ownerId,
"name": ownerName
}
}
])
for source in sources:
updateUrl = 'https://devrel.api.identitynow.com/v3/sources/' + source["id"]
headers = {
'Content-Type': 'application/json-patch+json',
'Authorization': 'Bearer ' + accessToken
}
updatedSource = requests.request("PATCH", updateUrl, headers=headers, data=patchBody).json()
print(f'Changed owner for {updatedSource["name"]} to {ownerName}')
print('Finished')
1 Like
Thank you Colin for this response as well as the script. This will be very helpful.