get a list of all arcgis items with arcgis python module

12534
10
03-31-2018 06:13 PM
JohnBroecher
New Contributor III

Is it possible to get a list of all arcgis online items with the python module?

10 Replies
DanPatterson_Retired
MVP Emeritus

This is the API reference https://esri.github.io/arcgis-python-api/apidoc/html/ 

What specifically is it you need?

0 Kudos
JohnBroecher
New Contributor III

Couldn't find anything in the reference. I'm looking for a way to get a list of all items in my AGO account.

0 Kudos
by Anonymous User
Not applicable

You could try searching using an owner filter like:

gis.content.search("owner:my_username", max_items=1000)

If you authenticate with your account, then it should find everything you own.

arcgis.gis module — arcgis 1.4.0 documentation 

RonnieRichards
Occasional Contributor III

The API reference above is correct. There is a search method which should do exactly what you need. 

 

0 Kudos
citrasagala
New Contributor

Maybe this script can help.

The output will export excel files contains all parameters like title, type, itemid, etc.

from arcgis.gis import GIS
import pandas as pd

portal = GIS("url portal", "username", "password")

#set "max_users" parameters in search() if you have more than 100 users in your portal
users_all = portal.users.search() 

def get_item(user):
       list_items = {}
       content_item = user.items()
       for item in content_item:
             list_items[item.itemid] = item
      
      folders = user.folders
       for folder in folders :
             folder_items = user.items(folder=folder['title'])
             for item in folder_items:
                     list_items[item.itemid] = item
       pd.DataFrame(list_items).transpose().to_excel(str(user.username)+'.xlsx')

for i in range(len(users_all)):
       print("extract "+ str(users_all[i]) + "data to excel...")
       get_item(users_all[i])‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
ConorMacNaughton
New Contributor II

If I don't have an enterprise portal where does the Excel end up? It doesn't show up in my organization's content in AGO. The script seems to run fine and loops through my users, but I can't figure out where the exports are located.

Is there something I can add to the script to download the Excel after its been exported?

0 Kudos
MarcGraham2
Occasional Contributor III

I know this is a bit old but you can just modify the script to specify an output location:

pd.DataFrame(list_items).transpose().to_excel('C:\\temp\\' + str(user.username)+'.xlsx')

@ConorMacNaughton wrote:

If I don't have an enterprise portal where does the Excel end up? It doesn't show up in my organization's content in AGO. The script seems to run fine and loops through my users, but I can't figure out where the exports are located.

Is there something I can add to the script to download the Excel after its been exported?


 

MarcGraham2
Occasional Contributor III

Great script thanks.

0 Kudos
ErnestoCarreras2
New Contributor III

The script is great! Thanks for sharing... I have been trying to perform this task but in my case, I just need to list the items inside a specific folder within AGOL's content folders. I like the way the original scripts outputs the table with title, type, itemid. Any assistance will be appreciated!