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?
Solved! Go to Solution.
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)
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)
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?
Helps if the account running the query has the right permissions to see ALL items, not just public ones!
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!