I need to be able to progammatically create Hosted Feaure Layer Views of a number of services which we collaborate to ArcGIS Online. This is to provide a community view of data we hold at Council level. I have found an excellent Python script - https://community.esri.com/t5/gis-life-blog/create-view-from-hosted-feature-layer-and-define/ba-p/898540 - which I have managed to hack to use our own data. This works perfectly when the source item consists of a single layer. However I am completely failing to make it work when the source layer for the view is a sublayer.
For example I want to create a community view of the Places theme of our Local Plan Policy areas - https://ren.maps.arcgis.com/home/item.html?id=805b7050bcfd4154a6a15f533eae7a52
https://services2.arcgis.com/fq3IIWzrdf1xBoPI/arcgis/rest/services/LDP_ADOPTED_2021/FeatureServer/6
using our Community Council boundaries - ItemID 0382e3a4a2e944858426ddde271211f0
e.g. places = gis.content.get('0382e3a4a2e944858426ddde271211f0').layers[1].query()
I just don't seem to be able to find a way to make this work. Any help gratefully received.