Multiple organizations listing Admins

Brandon_Fox_CSG
Here to help

Multiple organizations listing Admins

Hey all, i'm pretty new to Java and all these API calls, but I'm attempting to use Postman to pull my list of about 40 orgs and show me the admins across them...

 

I've attempted to run a for loop in the GET ListOrgs which then calls the next GET (GetAdmins) but it's not working and i'm only seeing the last item in the json.

 

I need to run the GetAdmins against all orgs returned in the GetOrgs... can anyone help?

 

My code:

 

tests["Status code is 200 (that's good!)"] = (responseCode.code === 200);

if (responseCode.code === 200) {
    
    var jsonData = pm.response.json();
    var json = [];
    
    postman.setEnvironmentVariable("json", jsonData)
    postman.setNextRequest('GetAdmins');
    
  for (var key in jsonData ) {
        if (jsonData.hasOwnProperty(key)) {
            postman.setEnvironmentVariable("organizationId", jsonData[key].id)
            postman.setEnvironmentVariable("orgname", jsonData[key].name)
            tests[jsonData[key].name + " " + jsonData[key].id] = !!jsonData[key].name;
        }
    }
}

else {
    postman.setNextRequest(null);
}

Thanks in advance!

1 REPLY 1
Seshu
Meraki Employee
Meraki Employee

Go ahead and check out the Python Script I wrote.

For MSP Admin Change:

1. Lists all Admins in All the Orgs

2. You can Add/Remove/Update Per Network privileges of the admin

 

Snippet is given below. The whole Code is here(https://drive.google.com/open?id=19Pr_7b4UP0A0zpcXCjn23S-6AbbTQa1B). 

iter_org = int(0)
for entryOrg in orgs.json():
bool_inOrgBeforeSubmit = False
bool_inOrgAfterSubmit = False
str_adminId = None

#Find if the admin was an existing admin in the org
for entry in multiOrgAdminList:
if entry['orgId'] == entryOrg['id']:
bool_inOrgBeforeSubmit = True
str_adminId = str(entry['adminId'])

iter_org += 1
orgAccess = str(win.getOptionBox(str(entryOrg['id'])))
if orgAccess != "none":
bool_inOrgAfterSubmit = True
url = base_url + entryOrg['id'] + "/networks"
networks = requests.get(url, headers=header)
submitNetworkAccessList = []
for entryNw in networks.json():
networkAcess = str(win.getOptionBox(str(entryNw['id'])))
if networkAcess != "none":
bool_inOrgAfterSubmit = True
temp = {'id': entryNw['id'], 'access': networkAcess}
submitNetworkAccessList.append(temp)
if bool_inOrgAfterSubmit:
str_email = win.getEntry("multiAdmin_email")
str_userName = win.getEntry("multiAdmin_name")
#Verify if the admin is in the org
#if the admin is in the org and access privilege changes, UPDATE
for entry in multiOrgAdminList:
if entry['orgId'] == entryOrg['id']:
if str(entry['networks']) != str(submitNetworkAccessList):
url = base_url + str(entryOrg['id']) + "/admins/" + str_adminId
payload = {'name': str_userName, 'email': str_email, 'orgAccess': orgAccess,
'networks': submitNetworkAccessList}
temp = requests.put(url, json.dumps(payload), headers=header)
print("Updated in the Org:", entryOrg['name'])
print(temp)
#If the admin is not in the org, ADD
if bool_inOrgBeforeSubmit == False:
url = base_url + str(entryOrg['id']) + "/admins"
payload = {'name': str_userName, 'email': str_email, 'orgAccess': orgAccess,
'networks': submitNetworkAccessList}
temp = requests.post(url, json.dumps(payload), headers=header)
print("Add to the Org:", entryOrg['name'])
print(temp)
#print(orgAccess, submitNetworkAccessList)
elif bool_inOrgBeforeSubmit:
#If the admin was there and now there now, DELETE
url = base_url + str(entryOrg['id']) + "/admins/" + str_adminId
temp = requests.delete(url, headers=header)
print("Removed from the Org:", entryOrg['name'])
print(temp)
else:
#Admin was not in the org before submit and after submit
print("No change in the Org:", entryOrg['name'])

 

Get notified when there are additional replies to this discussion.