<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Get Users and Other info from AGOL User Store in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1261610#M8408</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/433412"&gt;@Kepa&lt;/a&gt;&amp;nbsp; Thanks so much this is exactly what I was looking for.... I posted my script below incase anyone wants to reference....&lt;/P&gt;&lt;P&gt;I am writing this to a CSV file as well as displaying in a data frame&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
import arcgis 
import pandas as pd
import csv

agol_username = 'xyzxyzx' 
agol_password = 'xyzxyzx'  
output_csv = r'C:\Users\Desktop\GIS_projects\AGOL_Python\users.csv'
search_user = '*'
gis = GIS('https://xyzx.maps.arcgis.com', agol_username, agol_password)
user_list = gis.users.search(query=search_user, max_users=5)
roles = gis.users.roles.all()
rol_ids = {role.role_id: role.name for role in roles}
output = []
counter = 0

with open(output_csv, 'w', encoding='utf-8') as file:
     csvfile = csv.writer(file, delimiter=',', lineterminator='\n')
     csvfile.writerow(["username",                         # these are the headers; modify according to whatever properties you want in your report
                       "email",
                       "roleID",
                       "level",
                       "disabled",
                       "role",
                       "licenseType"
                     ])
     for user in user_list:
        try:
            varusername = user.username  
            varemail = user.email
            varRoleID = rol_ids[user.roleId]
            varlevel = user.level
            vardisabledValue = user.disabled
            varrole = user.role
            varlicenceType = user.userLicenseTypeId

            z = (varusername if isinstance(varusername, list) else [varusername]) + [varemail] + [varRoleID] + [varlevel] + [vardisabledValue] +  [varrole] + [varlicenceType]
            output.append(z)

            counter += 1
            csvfile.writerow([varusername,  
                        varemail,
                        varRoleID,
                        varlevel,
                        vardisabledValue,
                        varrole,
                        varlicenceType 
                        ])
        except KeyError as e:
            print(user.username, e)

df = pd.DataFrame(output,columns=['name','email','RoleID','Level','disabled','role','licensetype'], dtype=float)
print(df)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jun 2024 16:45:13 GMT</pubDate>
    <dc:creator>kapalczynski</dc:creator>
    <dc:date>2024-06-28T16:45:13Z</dc:date>
    <item>
      <title>Get Users and Other info from AGOL User Store</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260842#M8389</link>
      <description>&lt;P&gt;I am trying to write a script that will get me the users, email, user name, User Type and Role&lt;/P&gt;&lt;P&gt;I can do the below but cant find the type for User Type and Role&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any thoughts on how to get their User Type and Role?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;from arcgis.gis import GIS
import arcgis 
import pandas as pd



agol_username = 'xyz' 
agol_password = '\xyz'  
output_csv = r'C:\Users\Desktop\projects\AGOL_Python\users.csv'

search_user = '*'
gis = GIS('https://xyz.maps.arcgis.com', agol_username, agol_password)
user_list = gis.users.search(query=search_user, max_users=2000)

output = []
for item in user_list:

    email = item.email
    username = item.username
    z = [email] + (username if isinstance(username, list) else [username])
    print(z)
    output.append(z)
print("")
print(output)


df = pd.DataFrame(output,columns=['name','email'], dtype=float)
print(df)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 16:41:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260842#M8389</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-06-28T16:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Get Users and Other info from AGOL User Store</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260860#M8390</link>
      <description>&lt;P&gt;You are in the right way, you just need to go further on the user object properties:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Level 1 = Viewer , 2 = Creator, not sure about Editor &amp;amp; Mobile worker levels
item.level
item.role
item.userLicenseTypeId&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#user" target="_blank" rel="noopener"&gt;Python API Reference (User)&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 14:02:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260860#M8390</guid>
      <dc:creator>Kepa</dc:creator>
      <dc:date>2023-02-23T14:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Get Users and Other info from AGOL User Store</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260876#M8392</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;I get this return ... where do I get a list of values for LEVEL?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RETURN:&lt;/P&gt;&lt;P&gt;['gg.ggg@xyz.xyz', 'xy.xyz@xyz.xyz', '11', 'org_user', 'fieldWorkerUT']&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I define 11?&lt;/P&gt;&lt;P&gt;What is org_user?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 16:42:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260876#M8392</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-06-28T16:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: Get Users and Other info from AGOL User Store</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260885#M8394</link>
      <description>&lt;P&gt;Fir instance this is one return&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;['xyz.xyz@xyz.gov', 'xyz.xyz@xyz.gov', '2', 'org_admin', 'creatorUT']&lt;/P&gt;&lt;P&gt;2 = Creator?&lt;/P&gt;&lt;P&gt;org_admin is not my role I see when I look this person up in AGOL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This person is a Creator and has a Custom Role of Publisher+&lt;/P&gt;&lt;P&gt;What is 'creatorUT'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kapalczynski_0-1677162696617.png" style="width: 713px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/63508i70E5144497D36B83/image-dimensions/713x100?v=v2" width="713" height="100" role="button" title="kapalczynski_0-1677162696617.png" alt="kapalczynski_0-1677162696617.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 16:43:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260885#M8394</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-06-28T16:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: Get Users and Other info from AGOL User Store</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260918#M8396</link>
      <description>&lt;P&gt;There are three possible values under role property:&lt;/P&gt;&lt;P&gt;org_user&lt;SPAN&gt;,&amp;nbsp;&lt;/SPAN&gt;org_publisher&lt;SPAN&gt;&amp;nbsp;and&amp;nbsp;&lt;/SPAN&gt;org_admin&lt;/P&gt;&lt;P&gt;The only explanation for what you get is that custom roles are named as 'org_admin'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Snipaste_2023-02-23_16-16-49.png" style="width: 451px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/63520i22D0272424768AFA/image-dimensions/451x124?v=v2" width="451" height="124" role="button" title="Snipaste_2023-02-23_16-16-49.png" alt="Snipaste_2023-02-23_16-16-49.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 15:17:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260918#M8396</guid>
      <dc:creator>Kepa</dc:creator>
      <dc:date>2023-02-23T15:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: Get Users and Other info from AGOL User Store</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260929#M8397</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to query the user and get back their Role that is assigned via AGOL.&lt;/P&gt;&lt;P&gt;I query the users and get values that are not the same values as when you add a new Member.&amp;nbsp; This is VERY confusing.&amp;nbsp; If I am trying to add a user programmatically I see Mobile Worker in AGOL but:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;when I query via python I see fieldWorkerUT.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;They are a creator and when I query I get 2&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I need to be able to bridge these terminologies so I can query and modify users programmatically.&lt;/P&gt;&lt;P&gt;For example when I query this person I get this:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;['xyzx@xyzx.gov', 'xyzx@xyzx.gov', '11', 'org_user', 'fieldWorkerUT']&lt;/P&gt;&lt;P&gt;BUT when I look at this users in AGOL I get this:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MobileWorker and Data_Editor (which is a custom Role)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kapalczynski_1-1677166126928.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/63523i5D4EADCD8DD66F47/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kapalczynski_1-1677166126928.png" alt="kapalczynski_1-1677166126928.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I assume that fieldWorkerUT and Mobile Worker are the same thing?&lt;/LI&gt;&lt;LI&gt;How to I query for the custom role that is set for this user?&lt;/LI&gt;&lt;LI&gt;If I want to add a user programmitically do I say fieldWorkerUT or MobileWorker&lt;/LI&gt;&lt;LI&gt;How would I refer to the custom role (Data_Editor vs org_user)&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 16:44:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260929#M8397</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-06-28T16:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: Get Users and Other info from AGOL User Store</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260942#M8398</link>
      <description>&lt;P&gt;If I use this admin tool I can read all the users&lt;/P&gt;&lt;P&gt;And it reads it correct... When Cant I do that via python&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kapalczynski_1-1677167955765.png" style="width: 750px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/63527i19B1C144C82E361F/image-dimensions/750x357?v=v2" width="750" height="357" role="button" title="kapalczynski_1-1677167955765.png" alt="kapalczynski_1-1677167955765.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 15:59:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1260942#M8398</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2023-02-23T15:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: Get Users and Other info from AGOL User Store</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1261315#M8400</link>
      <description>&lt;P&gt;Digging into the API reference you can get the custom role ids this way:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;roles = gis.users.roles.all()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Create a dictionary with role ids, which gives us ID:roleName key-value pairs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;rol_ids = {role.role_id: role.name for role in roles}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, use the roleId property of user's object to get the name like this (I used an exception to catch default roles of the organization):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for user in users:
    try:
        print(user.username, rol_ids[user.roleId])
    except KeyError as e:
        print(user.username, e)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Hope that helps!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2023 07:18:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1261315#M8400</guid>
      <dc:creator>Kepa</dc:creator>
      <dc:date>2023-02-24T07:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: Get Users and Other info from AGOL User Store</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1261320#M8401</link>
      <description>&lt;P&gt;1. Yeah, I think so, but AGOL is always evolving so the exact name could change in the future&lt;/P&gt;&lt;P&gt;2. Answered below&lt;/P&gt;&lt;P&gt;3. and 4. When calling &lt;EM&gt;create&lt;/EM&gt; method when adding users you can assign a custom role passing the specific role ID in the &lt;EM&gt;role&lt;/EM&gt; parameter.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2023 07:31:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1261320#M8401</guid>
      <dc:creator>Kepa</dc:creator>
      <dc:date>2023-02-24T07:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get Users and Other info from AGOL User Store</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1261610#M8408</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/433412"&gt;@Kepa&lt;/a&gt;&amp;nbsp; Thanks so much this is exactly what I was looking for.... I posted my script below incase anyone wants to reference....&lt;/P&gt;&lt;P&gt;I am writing this to a CSV file as well as displaying in a data frame&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
import arcgis 
import pandas as pd
import csv

agol_username = 'xyzxyzx' 
agol_password = 'xyzxyzx'  
output_csv = r'C:\Users\Desktop\GIS_projects\AGOL_Python\users.csv'
search_user = '*'
gis = GIS('https://xyzx.maps.arcgis.com', agol_username, agol_password)
user_list = gis.users.search(query=search_user, max_users=5)
roles = gis.users.roles.all()
rol_ids = {role.role_id: role.name for role in roles}
output = []
counter = 0

with open(output_csv, 'w', encoding='utf-8') as file:
     csvfile = csv.writer(file, delimiter=',', lineterminator='\n')
     csvfile.writerow(["username",                         # these are the headers; modify according to whatever properties you want in your report
                       "email",
                       "roleID",
                       "level",
                       "disabled",
                       "role",
                       "licenseType"
                     ])
     for user in user_list:
        try:
            varusername = user.username  
            varemail = user.email
            varRoleID = rol_ids[user.roleId]
            varlevel = user.level
            vardisabledValue = user.disabled
            varrole = user.role
            varlicenceType = user.userLicenseTypeId

            z = (varusername if isinstance(varusername, list) else [varusername]) + [varemail] + [varRoleID] + [varlevel] + [vardisabledValue] +  [varrole] + [varlicenceType]
            output.append(z)

            counter += 1
            csvfile.writerow([varusername,  
                        varemail,
                        varRoleID,
                        varlevel,
                        vardisabledValue,
                        varrole,
                        varlicenceType 
                        ])
        except KeyError as e:
            print(user.username, e)

df = pd.DataFrame(output,columns=['name','email','RoleID','Level','disabled','role','licensetype'], dtype=float)
print(df)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 16:45:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/get-users-and-other-info-from-agol-user-store/m-p/1261610#M8408</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-06-28T16:45:13Z</dc:date>
    </item>
  </channel>
</rss>

