Update Org Admin

jwalls
Conversationalist

Update Org Admin

We are looking to use the API to create, modify and delete admin accounts from our AD in security groups. I have a test user I created the account for just fine, and I find and delete said user pretty easily with a little POSH work. However, when I run the update command, it processes "successfully" but the user isn't updated.

 

We use the "orgAccess" field to denote read/write privileges since our setup is simple. We have a few users who are "read-only" and some network guys that are "full." I'd also like to be able to update the name and/or email address based on HR required name changes.

 

My script is below. Any advice would be great. Thank you.

-----------------

 

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Headers.Add("Accept", "*/*")
$Headers.Add("X-Cisco-Meraki-API-Key", "$Key")

 

<#  GET LIST OF USERS AND NARROW TO REQUESTED  #>
$Response = Invoke-RestMethod 'https://$($Key).meraki.com/api/v0/organizations/$($Org)/admins' -Method 'GET' -Headers $Headers
$NDX = $Response.email.IndexOf("%Email%")
$User = $Response[$NDX]

 

<#  SET NEW VARIABLES  #>
$URL = 'https://$($Base).meraki.com/api/v0/organizations/$($Org)/admins/'+$user.id
$Body2 = '{
`n "name": "$($DisplayName)",
`n "email": "$($Email)",
`n "networks": [],
`n "tags": [],
`n "orgAccess": "$($AccessType)"
}'

 

<#  UPDATE ACCOUNT  #>

$Response2 = Invoke-RestMethod $URL -Method 'PUT' -Headers $Headers -Body $Body2
$Response2

2 Replies 2
Edgar-VO
Building a reputation

Good Morning,

 

I am not really sure how this works with PowerHell but it works fine with python.. I have tested it on my own littlle organisation...

 

i ran into one issue and i think you have that same problem...

 

response = dashboard.admins.updateOrganizationAdmin(org_id,user_id,**admin)
TypeError: updateOrganizationAdmin() got multiple values for argument 'id'

 

I had to remove the id from the list and add it as a separate value to the API. When i did that, my Display name changed. 

 

 

import meraki
import apikey

api_key = apikey.Get_Api_Key("")
dashboard       = meraki.DashboardAPI(api_key)
my_org = dashboard.organizations.getOrganizations()

for org in my_org:
        org_id = org['id']
        
my_admin = dashboard.admins.getOrganizationAdmins(org_id)

for admin in my_admin:

    if admin['email'] == "xxxxx@xxxx.com":
        admin['name'] = "Maestro"
        user_id = admin['id']
        del admin['id']

        response = dashboard.admins.updateOrganizationAdmin(org_id,user_id,**admin)
        
jwalls
Conversationalist

Hey there, and thank you. I see what you're doing there. I'll give that a try!
Get notified when there are additional replies to this discussion.