Hi there - I'd like to have a script input parameter that ultimately returns the ArcGIS Online item ID for a hosted feature layer for updating that item in a webmap. Using a 'feature layer' parameter returns the REST URL of that hosted layer.
Using REST would seemingly require the user to have to enter a name/password and generate a token just to get the ID of that hosted feature layer. Is there a way around this?
Solved! Go to Solution.
You can use the Featureclass input (selecting it from the Portal content in catalog), then in the code you can get the item Id:
import arcgis
from arcgis.features import FeatureLayer
# you can probably use the existing connection from pro if they are already signed in.
gis = arcgis.GIS("https://<domain>.maps.arcgis.com", client_id="AppId")
# this would be the feature service address that is from the input parameter
fs_url = 'https://services9.arcgis.com/435tk5oo45nwo/arcgis/rest/services/trips/FeatureServer'
# get the item using the url
in_service = FeatureLayer(fs_url)
props = in_service.properties
# print item id
arcpy.AddMessage(props.serviceItemId)
C
You can use the Featureclass input (selecting it from the Portal content in catalog), then in the code you can get the item Id:
import arcgis
from arcgis.features import FeatureLayer
# you can probably use the existing connection from pro if they are already signed in.
gis = arcgis.GIS("https://<domain>.maps.arcgis.com", client_id="AppId")
# this would be the feature service address that is from the input parameter
fs_url = 'https://services9.arcgis.com/435tk5oo45nwo/arcgis/rest/services/trips/FeatureServer'
# get the item using the url
in_service = FeatureLayer(fs_url)
props = in_service.properties
# print item id
arcpy.AddMessage(props.serviceItemId)
C
that's exactly what I was hoping for - thank you!