Discrepancies accessing AGO Community users through REST API using PortalPy

2951
6
12-05-2014 11:54 AM
HeathBrackett1
Occasional Contributor II

I am using the Python Module, PortalPy, found on GitHub to write scripts to run administrative tasks in ArcGIS Online.  PortalPy is great because it keeps me from having to access the REST API myself, which is something I'm not very familiar with.  But I'm running into discrepancies in what is being returned and I'm not sure whether the inconsistency is within the REST API or the PortalPy module.  There are two functions within the module - get_org_users and get_user - that I am having trouble with at the moment

Our organization has implemented custom roles.  I have a script that stores each member's information in json format so that I can access relevant information outside of AGO.  The problem is:

get_org_users returns true 'role' for every user (including custom roles) but returns an empty list for 'groups' for each user. get_user returns only ESRI-defined 'role' for each user (custom role value returned defaults back to ESRI-defined template that custom role is based on?) but returns a populated dictionary for 'groups' for each user.

I need to have the user's true 'role' and 'groups' in the same json file.  Can anybody explain why the two functions do not produce the same results? 

Thanks,

Heath

0 Kudos
6 Replies
AlexanderNohe1
Occasional Contributor III

Hello Heath Brackett‌,

The method call to get_org_users makes a REST call to: <PortalURL>/sharing/rest/portals/self/users

where as the method call to get_user makes a REST call to: <PortalURL>/sharing/rest/community/users/<USERNAME>

I hope this helps!

HeathBrackett1
Occasional Contributor II

I understand that.  But I don't understand why the responses provide different results.

The user['role'] property honors custom roles when accessed via <PortalURL>/sharing/rest/portals/self/users.  If you access the user['role'] property via <PortalURL>/sharing/rest/community/users/<USERNAME>, the response is never a custom role - it seems to always default to the ESRI standard role template that was used to create the custom role.  Why isn't the same value populated in each location? The REST API documentation does not address this.

Conversely, according to the REST API documentation, user['groups'] property coming from .../portals/self/users is a list of the groups that user is a member of, but it always returns an empty list (why is this list empty?).  The user['groups'] property coming from .../community/users/<USERNAME> returns an array of all of the groups that a user is a member of.  Is there a reason that the user['groups'] property must be a list instead of an array when accessed via .../portals/self/users?

This is all very confusing.  I get the feeling that ESRI is not aware that these calls aren't returning appropriate results.

Heath

0 Kudos
JoseSanchez
Occasional Contributor III

Does it run only in ArcGIS 10.5? 

In 10.2.2 the library "import portalpy" is missing.

Thanks

0 Kudos
AlexanderNohe1
Occasional Contributor III

Portlapy is an open source library that can be located here:

GitHub - Esri/portalpy: A module that allows you to administer Portal for ArcGIS and ArcGIS Online. 

This library is not included with ArcGIS Desktop.

0 Kudos
JoseSanchez
Occasional Contributor III

Can I use my AGOL to test this list_admins.py?     http://[my Organization].maps.arcgis.com      or does it work only with a local  portal?

I am trying to test it with: 

portalUrl           = "http://[my Organization].maps.arcgis.com/arcgis"   or  "http://[my Organization].maps.arcgis.com"
portalAdminUser     = "my User Id"
portalAdminPassword = "my Password"

and it shows the following error message:

Traceback (most recent call last):
  File "C:\Workspace\portalpy-master\list_admins.py", line 32, in <module>
    portal = portalpy.Portal(portalUrl, portalAdminUser, portalAdminPassword)
  File "C:\Workspace\portalpy-master\portalpy.py", line 121, in __init__
    referer, proxy_host, proxy_port)
  File "C:\Workspace\portalpy-master\portalpy.py", line 1800, in __init__
    self.login(username, password, expiration)
  File "C:\Workspace\portalpy-master\portalpy.py", line 1815, in login
    newtoken = self.generate_token(username, password, expiration)
  File "C:\Workspace\portalpy-master\portalpy.py", line 1809, in generate_token
    resp = self.post('generateToken', postdata, ssl=True)
  File "C:\Workspace\portalpy-master\portalpy.py", line 2016, in post
    resp = opener.open(url, data=encoded_postdata)
  File "C:\Python27\ArcGISx6410.2\lib\urllib2.py", line 410, in open
    response = meth(req, response)
  File "C:\Python27\ArcGISx6410.2\lib\urllib2.py", line 523, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python27\ArcGISx6410.2\lib\urllib2.py", line 448, in error
    return self._call_chain(*args)
  File "C:\Python27\ArcGISx6410.2\lib\urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "C:\Python27\ArcGISx6410.2\lib\urllib2.py", line 531, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 404: Not Found

0 Kudos
AlexanderNohe1
Occasional Contributor III

I believe that you should be able to use your ArcGIS Online account to access.

I would check three things:

1) Ensure that your username matches exactly how it appears in ArcGIS Online (case sensitivity).

2) Ensure that you are not restricted to SSL Only in your organization.

3) Ensure that you are logged in with a user that has those permissions.

Since I am not a member of the python team, I would encourage that you direct your questions to the issues section of the repository: Issues · Esri/portalpy · GitHub   Here, you will be able to reach out directly to the developers of this module and they can help answer questions / resolve issues with the source code.

0 Kudos