Good morning,
I am looking for a way to select all hosted feature classes that belong to a specific group
items = gis.content.search(query='')
You can do this at least two ways:
Like this:
group_id = "1234_your_group_id_5678"
gis.content.search(query=f"group: {group_id}", item_type="Feature Service")
or like this:
group_id = "1234_your_group_id_5678"
group = gis.groups.get(group_id)
group.search(query="type:Feature Service")
Thank you @EarlMedina
This is what I wrote and it works:
# Retrieve Group ID
group = GIS.groups.get(group_id)
print (group)
# List all feature layers collections in the group
feature_layer_collections = []
for item in group.content():
## print (item)
## print (item.type)
## print (item.id)
# Filter for feature layer items
if item.type == "Feature Service":
#Get the Feature Layer Collection
flc = FeatureLayerCollection.fromitem(item)
feature_layer_collections.append(flc)
#print ("Append")
# Create a unique export title based on the item name and timestamp
# Create a datetime object
now = datetime.datetime.now()
formatted_date = now.strftime("%Y%m%d_%H:%M:%S")
## export_title = f"{item.title}_backup_{formatted_date}"
export_title = f"{formatted_date}_backup_{item.title}"
# Export the item to File Geodatabase format
print(f"Exporting {item.title}...")
export_item = item.export(title=export_title, export_format="File Geodatabase",parameters=None,wait=True)
# Download the exported file to the backup directory
export_path = os.path.join(backup_directory, f"{export_title}.zip")
export_item.download(backup_directory)
# Clean up the export item from ArcGIS Online
export_item.delete()
@SanchezNuñez Wanted to say thank you for this gem. This is exactly what I have been working on to help staff manage there data from various field project in AGOL. Thank you!