Hello,
I am creating a program using the ArcGIS Python API to go through all content within my organization (ArcGIS Online and Portal) and "audit" it: returning information like the item ID, how it is shared, any groups it is in, whether or not it is delete protected, created and modified dates, etc.
I would like to also know whether content is hosted within my organization or if it is a referenced service layer. Is there a way to do this with the API? There does not seem to be a corresponding item property, the same way there is item.id, item.url, etc, and I have not been able to find any documentation on how to find this.
Thanks for any help or documentation links!
Solved! Go to Solution.
Hi Anna,
You can list all feature layers hosted using gis.admin module.
See sample below:
from arcgis.gis import GIS
gis = GIS("https://votreNomDomaine/portal", "login", "password")
server = gis.admin.servers.list()[0]
count=1
for service in server.services.list('Hosted'):
print('{} {}'.format(count, service))
count+=1
Hope this help you,
Best regards,
Fred
Hi Anna,
Another more elegant code is to check if the property typeKeywords of the item has the text 'hosted Service' include in his list.
Retrieve code below:
from arcgis.gis import GIS
gis = GIS("https://votreNomDomaine/portal", "login", "password")
items = gis.content.search('*',item_type="Feature Layer", max_items=25)
itemsHosted = [item.title for item in items if 'Hosted Service' in item.typeKeywords]
print(itemsHosted)
Hope this help you,
Best regards,
Fred
I'm assuming that you mean a layer you've added from another org, not a basemap reference layer?
To find out where the layer is originating from, you can call the url property on most operational layers.
lyrs = gis.content.search('some search for layers')
for lyr in lyrs:
print(l.url)
If a content item isn't a service, you'll just get None, but otherwise, you'll get the origin URL of the service.
Does that help?
I suppose if you stored your hosting server as an attribute, you could simply check
my_url = 'some-server-url'
if lyr.url == my_url:
print('internal')
else:
print('external')
Are you doing this on AGOL or a private Portal? There are some differences in what we're able to do depending on which.
I have noticed that the most recent update to AGOL added this sort of thing:
So there does seem to be some way to track whether an item is coming from an outside org...
Thanks for your replies! I found that one can determine if the item type matches any possible hosted types (all potential types can be found here) and then look for the enterprise specific 'Hosted' directory in the url, see below:
potential_hosted_types = list('all potential types here')
#loop through the list to see if our item type is a match
for potential_type in potential_hosted_types:
if item.type in potential_type:
maybe_hosted = True
else:
maybe_hosted = False
#See if the item is in the Hosted directory
if maybe_hosted == True:
if 'Hosted' in item.url:
item_hosted = True
else:
item_hosted = False
else:
item_hosted = False
I am not sure how to do something similar for items in ArcGIS online since there is no Hosted directory.
Hi Anna,
You can list all feature layers hosted using gis.admin module.
See sample below:
from arcgis.gis import GIS
gis = GIS("https://votreNomDomaine/portal", "login", "password")
server = gis.admin.servers.list()[0]
count=1
for service in server.services.list('Hosted'):
print('{} {}'.format(count, service))
count+=1
Hope this help you,
Best regards,
Fred
Hi Anna,
Another more elegant code is to check if the property typeKeywords of the item has the text 'hosted Service' include in his list.
Retrieve code below:
from arcgis.gis import GIS
gis = GIS("https://votreNomDomaine/portal", "login", "password")
items = gis.content.search('*',item_type="Feature Layer", max_items=25)
itemsHosted = [item.title for item in items if 'Hosted Service' in item.typeKeywords]
print(itemsHosted)
Hope this help you,
Best regards,
Fred