Environment: Running ArcGIS API for Python version 2.0.1 from Pro 3.0.2.
I am trying to use the ArcGIS API for Python to create a view of an AGOL hosted feature layer and set a definition query. This guide seems to be the most definitive documentation of the process, but it's not working for me. Here is the code I have that follows this process:
from arcgis import GIS
from arcgis.features import FeatureLayerCollection
source_item_id = '<your item id>'
view_def = {
'viewDefinitionQuery': "State_FIPS IN ('09','23','25','33','44','50')"
}
view_name = 'TEST_create_view_python_01'
gis = GIS(profile='AGOL')
source_item = gis.content.get(source_item_id)
source_flc = FeatureLayerCollection.fromitem(source_item)
new_view = source_flc.manager.create_view(name=view_name)
view_search = gis.content.search(view_name)[0]
view_flc = FeatureLayerCollection.fromitem(view_search)
service_layer = view_flc.layers[0]
service_layer.manager.update_definition(view_def)
I copied the definition query from a view I manually created in a browser, so I'm pretty sure that's correct. It runs without errors or warnings. The new view shows up as an AGOL item, but when I add the view to a webmap, I see this error:
And adding it to a map in Pro gives me this:
Next, I tried one little tweak. After defining the source_flc variable, I create a list of layers and pass that to the create_view function's view_layers parameter. Otherwise, the code is the same:
view_layers = [source_flc.layers[0]]
new_view = source_flc.manager.create_view(name=view_name, view_layers=view_layers)
I can add it to Pro and it renders fine, but the popups are just a regular attribute field display, not my custom popup.I went to edit the popups in my layer and found that the Visualization tab (where you set the popup) is missing!
When I click "Open in Map Viewer", nothing loads.
If I use the "Add" button, the view shows up. If I click the "+Add" button, it changes to an "X Remove" button, but nothing shows up in the layer list or renders on the map.
I can manually create a working view in a web browser. I am getting errors when I try this with other source layers. So this doesn't seem like a data issue. What am I doing wrong?