Reading the API documentation here:
https://developers.arcgis.com/documentation/portal-and-data-services/portal-service/content-items/ho...
I am not seeing the ability to generate a list of all items shared to the world or shared to specific groups for example.
I would assume I should be able to do something like:
List all items.
for each item
identify sharing status (owner, org, to the world, list of groups)
if shared to the world
do something
Is this not possible?
Thanks,
James
Hi @JamesHood
You are looking for the Item object SharingManager shared_with property.
This should help get you started...
from arcgis.gis import GIS
agol = GIS("home")
items = agol.content.search(query="", max_items=10000)
for item in items:
share_details = item.sharing.shared_with
if share_details["level"].value == "EVERYONE":
print("Shared Publicly")
elif share_details["level"].value == "PRIVATE":
print("Shared with Owner")
elif share_details["level"].value == "ORGANIZATION":
print("Shared with Organization")
print("In these groups: ", [g.title for g in share_details["groups"]])
All the best,
Glen
If you have a lot of content in your organization, you will find it faster to include your search constraints directly in the search. Such an approach is identical to what happens when you use the GUI for searches like this.
For example, if you want to get a list of items "shared to the world" in the GUI, then you would go to the Content view, and filter Sharing to "Everyone (public)". The equivalent with the ArcGIS API for Python is the Item search() method, including the "access" parameter to filter on a sharing level of "public":
publicly_shared_items = gis.content.search(
query = "1=1", # scopes search to examine all content
filter = "access:public" # filters results to publicly accessible content
)If you do have a lot of content in your organization, then I would recommend switching from search() to advanced_search(), as the latter supports paging for efficiency and improved performance.
(Also, use the search method's filter parameter, rather than query, to specify "access:public". Filter is the preferred option when you want to search for exact parameter values; see Query Vs Filter in the underlying REST API.)
For identifying a list of items "shared to specific groups", the starting point in the GUI would be to go to each group and view their content. Similarly, with the ArcGIS API for Python, you would use the Group search() method to generate a list of items shared to a group:
# Retrieve the group whose contents you want to list.
# (You could also search for the group by title or other properties using GroupManager's search method.)
group = gis.group.get('id_of_group')
# Retrieve a list of items shared with the group.
items_shared_with_group = group.search(
query = "*"
)If you expect any group to have more than 100 items shared with it, then leverage the paging support in the Group search() method. For example, expanding on the above example:
# Retrieve the group whose contents you want to list.
# (You could also search for the group by title or other properties using GroupManager's search method.)
group = gis.group.get('id_of_group')
# Compile a list of items shared with the group.
items_shared_with_group = []
# Set initial record start parameter to 0. This will be incremented for each search batch.
next_start = 0
# Loop until there are no more search results to return, as indicated by nextStart = -1.
while(next_start != -1):
# Retrieve batch of search results
result = group.search(
query = "1=1", # scopes search to examine all content
max_items = 100, # do not set higher than 100, or a bug will return duplicate results
start = next_start # start from end of last batch of search results
)
# If there are results returned, add them to the list of items shared with the group.
if( 'results' in result ):
items_shared_with_group.extend(result['results'])
# Update the starting record for the next batch (-1 indicates no more batches to return)
next_start = result['nextStart']
# Display count of items found shared with group
print(len(items_shared_with_group))And, if you want to generate a list of items across multiple groups, then wrap the above code block with another loop that iterates through each group, and generates an overall, aggregated list of items.