ArcGIS Online Python API – How to Search Folder Items in ArcGIS Online

arcgis-onlinearcgis-portalarcgis-python-api

I want to have a list of the items inside a folder created by my user in AGOL, I want to use the ArcGIS API for Python.

so far I have found this:

import sys
from arcgis import gis
import os

sourceURL="https://yourAGOL.maps.arcgis.com"
sourceAdmin="adminUser"
sourcePassword="thisIsNotMyPassword"

clientAcronym = "Sales"
source = gis.GIS(sourceURL, sourceAdmin, sourcePassword)
existingItems = source.content.search('title:"{0}*" '.format(clientAcronym))

this code list all the items where their title start with Sales, but I know there is a folder called "Sales-Test" and it has some of those items, i want to know which items are inside of that folder:

if I get the list of my folders

me = source.users.me
me.folders
for folder in me.folders: 
    print(folder['title'])
    me.items(folder['title'])

I can see the folder "Sales-Test" but not he items inside it

In the Item documentation i cannot see how to get the folder information.
Is there a way to relate the information of existingItems with me.folders?

Best Answer

what if you add this:

    me = source.users.me
    me.folders
    for folder in me.folders: 
        print(folder['title'])
        me.items(folder['title'])
        itemsInFolders = me.items(folder=f['title'])  
        print(len(itemsInFolders))
        for i in itemsInFolders:
            print("      " +str(i.title))
Related Question