I'm looking at content_status property for 'authoritative' in the docs. I'm not sure how to use that as a parameter in a search. What I want to do is list all my 'authoritative' hosted feature layers and then download them.
I didn't think it would work, but I have tried:
from arcgis.gis import GIS
gis = GIS("", "", "")
my_content = gis.content.search(query="owner:" + gis.users.me.username,
item_type="Feature Layer",
content_status='authoritative',
max_items=15)
my_content
#error
TypeError: search() got an unexpected keyword argument 'content_status'
cont = my_content.content_status='authoritative'
cont
#error
AttributeError: 'list' object has no attribute 'content_status'
items= gis.content.search(content_status='authoritative')
#error
TypeError: search() got an unexpected keyword argument 'content_status'
Solved! Go to Solution.
auth_items = [i for i in gis.content.search('', item_type='Feature Layer', max_items=-1) if i.content_status == 'org_authoritative' or i.content_status == 'public_authoritative']
auth_items
A bit less efficient, but you could just iterate over all Feature Layer items and look directly at the property in question.
As you've noticed, content_status doesn't seem to be a searchable property in the standard content search.
Oddly, content status needs to be searched in the query string, and has to be done a couple different ways.
auth_items = gis.content.search('contentstatus:org_authoritative OR contentstatus:public_authoritative')
for item in auth_items:
# your download process
Edit: the page you ought to reference is this: https://developers.arcgis.com/rest/users-groups-and-items/search-reference.htm
But it looks like contentstatus isn't in the list. I've sent some feedback to get it added.
Thanks @jcarlson .
If it's is a query string why doesn't this result in anything?
auth_items = gis.content.search(
'contentstatus:org_authoritative AND contentstatus:public_authoritative')
for i in auth_items:
print(i)
I ran it with OR but for some reason I only got back a handful of Items from our orginization. And only one of these was mine when I know I have at least eight 'authoritative' layers alone.
Strange! "AND" won't work; as far as I can tell, an item can't have both statuses.
Try adding the parameter "max_items=-1"?
auth_items = gis.content.search('contentstatus:org_authoritative OR contentstatus:public_authoritative', max_items=-1)
for i in auth_items:
print(f'{auth_items.index(i):4} | {i.title}')
Returns
0 | 03-35 1 | Millbrook South Forest Preserve Trails 11x17 2 | 02-07 3 | Drainage Districts Oveview 4 | County Board District and Legislative and Congressional Districts 5 | 03-29
...
It's hard to say what that query string parameter is doing? The results I'm seeing range from dashboards to webmaps, not just feature layers. And only 1/4 I randomly looked at was 'authoritative'.
That print statement printed out 2045 orginization-wide items, which is basically every item in our AGOL account.
Well, anything can have "Authoritative" status. Add "item_type='Feature Layer'" to further filter that.
Odd that it would cast such a wide net. When I test it, it brings back the expected items.
Try watching your network traffic when you click the "Authoritative" filter in the content page and see what it's doing.
That's true, I didn't realize that. Regardless, I'm showing only 32 items with 'authoritative' status when viewing Content under My Organization.
That's interesting. I'm getting a Cross-Origin Request Blocked when clicking the 'Authoritative' filter.
16:11:50.370 Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events. (Reason: CORS request did not succeed).
auth_items = [i for i in gis.content.search('', item_type='Feature Layer', max_items=-1) if i.content_status == 'org_authoritative' or i.content_status == 'public_authoritative']
auth_items
A bit less efficient, but you could just iterate over all Feature Layer items and look directly at the property in question.
Thanks @jcarlson,
Not sure why your first bit of code wasn't giving me the same results as the second bit of code. But after adding this parameter to the second bit I was able to get the desired results.
query="owner:" + gis.users.me.username
I was signed as our org's admin user when I tested it. Perhaps that had some impact?
In any case, I'm glad you got it to return the results you want!