Loop through itemId

487
1
10-07-2019 08:38 AM
CliveSwan
Occasional Contributor II

Greetings,

I am trying to loop through the Portal Gallery to get the itemId for all maps and/or apps.

I can get the itemId for a single app calling the item = xx

e.g.

# item = "6f91e6d30e8b4776b23dccb2fc560c94"
# print(i['numViews'])

When I use the example in https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.apps.hub.html?highlight=itemid, get Attr...

import arcgis
from arcgis.gis import GIS
from arcgis import apps
from arcgis.apps import hub

url = "https://myarcgis.com/portal/home/gallery.html"

## https://myarcgis.com:7443/arcgis/home/content.html?start=1&view=grid&sortOrder=desc&sortField=modifi...

## url = "https://sslvwd1npxapp04.b-intra.net:7443/arcgis/home/content.html?sortOrder=desc&sortField=modified&..."

### Make a connection to the portal
gis = GIS(url=url)


myHub = gis.hub
a_Initiative = myHub.initiatives.get('itemId *')

for i in a_Initiative:
    print(I)

"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe" C:/Temp/DEV/GetPortalViewCounts.py
Traceback (most recent call last):
  File "C:/Temp/DEV/GetPortalViewCounts.py", line 7, in <module>
    from arcgis.apps import hub
ImportError: cannot import name 'hub'

Process finished with exit code 1

Regards,

Clive

 
Tags (2)
0 Kudos
1 Reply
JonathanQuinn
Esri Notable Contributor

I tried this on my side, not too sure why it expects it to be an Online organization when the docs indicate it can be an ArcGIS Enterprise deployment:

Might want to reach out to tech support or create an issue in the arcgis-python-api repo to see what's going on.

0 Kudos