Select to view content in your preferred language

Updating group member roles through Python API

1668
4
02-18-2019 11:33 AM
JamesMacCarthy
New Contributor

Is there a way to add a user to a group as a group admin using the "add_users" function in the python API? I saw there is a way to do this with the role parameter in the "invite_users" function but not sure why there isn't the same parameter for "add_users." Would rather just invite the user instead of requiring them to accept an invitation...

Also tried looking for a way to update group member roles through the python API and can't seem to find anything to elevate a group member from user to admin. Is this possible?

Thanks for any help you can provide!

0 Kudos
4 Replies
VishApte
Esri Contributor

I have a same problem in 10.7.1. There is no Python API to elevate user's role in a group.

I am working on large script to migrate portal named users to SAML log-ins. ArcGIS API for Python does not seem to have every REST API covered. I ended up making REST calls in some places where Python API doesn't exist or returns error. Here is a code for updating users' role in a group to group admin.

grp_user_role_url = r"{}/sharing/rest/community/groups/{}/updateUsers".format(base_portal_url, group_obj.id)
params = {'admins': user_obj.username,
          'token': portal_token,
          'f': 'json'}
encoded_params = urlencode(params).encode()
request = Request(grp_user_role_url, encoded_params)
request.add_header('Referer', base_portal_url)
rest_upd_user = urlopen(request).read().decode()
json_response = json.loads(rest_upd_user)
jorisfrenkel
Frequent Contributor

According to the documentation at arcgis.gis module | ArcGIS API for Python this should be possible by using the keyword "admin":

group.add_users(usernames=["User1234","User5678"], admin="Admin9012") 

But I haven't got this working.
I get the error message:

TypeError: add_users() got an unexpected keyword argument 'admin'

Maybe only working in Portal and not in ArcGIS Online?

 

0 Kudos
ShayneODonnell
New Contributor

I found there is an error in the documentation and the keyword needs to be passed in as "admins" not "admin".

jorisfrenkel
Frequent Contributor

It is working now for me in ArcGIS Online, but not in Pro. My Pro version is a bit older, so an older version of the API, maybe that's the problem. However, I have another issue (create a new user) that is not working in ArcGIS Online, but is working in Pro, so yeah, what should I use now...

0 Kudos