I am creating a table of all of my content items in ArcGIS Online and ArcGIS Enterprise. As a starting point, I am using the built-in vars() function to return all the Item attributes as a dictionary (.__dict__ can also be used with the same results). Here is my code (which is fast and works well):
# Log into ArcGIS Online
gis = GIS('home')
# Get all content items
qe = 'NOT owner:esri*'
items = gis.content.search(query=qe, max_items=-1, outside_org=False)
# Convert all Item class attributes to dictionary
items_dict = [vars(i) for i in items]However, vars() does not return all the Item attributes listed in the ArcGIS REST API documentation for Item. Most notably, the 'size' attribute is not returned, and for my purposes, this attribute is important. Why is 'size' not returned using the vars() method?
I was able to use the following code to get it to work, but it went from less than three seconds to 6 minutes(!):
items_dict = [vars(i) for i in items if i.size >= 0]
By initiating the 'size' class attribute, it is then included, but only if it is initiated like this.
I also have other code (see below; sourced from Managing ArcGIS Online Content with ArcGIS Dashboards and ArcGIS Notebooks) that returns a smaller subset of Item property information, including 'size', but fewer attributes. But, it doesn't work on ArcGIS Enterprise...Any help would be appreciated.
#From the REST URL, request all items in the organization.
#Create a dictionary of the results, and print out the output.
url = f'{gis.url}/sharing/rest/content/portals/{gis.properties.id}'
params = {
'f': 'csv',
'token': gis._portal.con.token
}
#Get a string response from the request and construct a DataFrame
csv_out = requests.get(url, params=params).text
df = pd.read_csv(io.StringIO(str(csv_out)))