Is it possible to query all users and return number of items owned by each?

2987
4
Jump to solution
03-17-2021 11:31 AM
ThomasColson
MVP Frequent Contributor

With

 

 

itemsList = gis.content.search(query = 'owner: GRSM_GIS',max_items = 10000)

fields = ['id','Title', 'Type', 'Scorecompleteness']

def kimFunc(txtPath):
    print ("in kimFunc")
    with open(txtPath, "w") as file:
        for item in itemsList:
            print(item)
            row = item.id,item.title,item.type,item.scoreCompleteness

            line = str(row)+"\n"
            file.write(line)

kimFunc('C:\\Temp\\PORTAL_INVENTORY\\DOCUMENT.txt')

 

I can easily get a list of items for one user. But what I need, is a list of users and the number of items they own. However, the list of response properties in https://developers.arcgis.com/rest/users-groups-and-items/user.htm doesn't indicate a number of items owned property. Am I out of luck?

Tags (2)
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

You could generate a list of users using the following code: 

 

users = gis.users.search(query=None, 
                         sort_field='email', 
                         sort_order='asc', 
                         max_users=700, 
                         outside_org=False, 
                         exclude_system=False)

 

 

Then, make the owner in your query dynamic and loop through each user: 

 

for user in users:
    # get username
    name = user.username
    # get items owned by user
    itemsList = gis.content.search(query = 'owner: {}'.format(name),max_items 
    = 10000)
    # get number of items
    owned_items = len(itemsList)
    # print the result (or write to a file, etc.)
    print ("{} owns {} items".format(name, owned_items))

 

 

(edit: a right parenthesis)

View solution in original post

4 Replies
by Anonymous User
Not applicable

You could generate a list of users using the following code: 

 

users = gis.users.search(query=None, 
                         sort_field='email', 
                         sort_order='asc', 
                         max_users=700, 
                         outside_org=False, 
                         exclude_system=False)

 

 

Then, make the owner in your query dynamic and loop through each user: 

 

for user in users:
    # get username
    name = user.username
    # get items owned by user
    itemsList = gis.content.search(query = 'owner: {}'.format(name),max_items 
    = 10000)
    # get number of items
    owned_items = len(itemsList)
    # print the result (or write to a file, etc.)
    print ("{} owns {} items".format(name, owned_items))

 

 

(edit: a right parenthesis)

ThomasColson
MVP Frequent Contributor

Very Very helpful, but for some reason, returning incorrect counts. For example, the script returns user a as having 3 "items", when in fact user a has 50 items. I wonder if its because most users with items have folders? And the code is not able to traverse folders? 

0 Kudos
ThomasColson
MVP Frequent Contributor

Helps if the account running the query has the right permissions to see ALL items, not just public ones!

0 Kudos
ThomasEdghill
Esri Community Moderator

I wanted to add here that ArcGIS Enterprise 10.9's recent addition of Administrative Reports can also achieve this easily - When you run a member report, the fields returned in the report includes the # of items owned by each member. According to the documentation, this number can also include items that aren't listed in the user's content, such as offline map areas. I hope this helps! 

0 Kudos