Select to view content in your preferred language

Input Parameter: Get hosted feature layer ID?

633
2
Jump to solution
04-10-2023 12:54 PM
SH_DH
by
New Contributor III

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?

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

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

 

View solution in original post

2 Replies
by Anonymous User
Not applicable

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

 

SH_DH
by
New Contributor III

that's exactly what I was hoping for - thank you!

0 Kudos