I'm trying to share / publish a Feature Layer to my AGOL account as a Hosted Feature Layer using arcpy
. I was able to do this using ArcGIS Pro and want to automate it. I use R / reticulate, code is below.
## start up ArcGIS
library(arcgisbinding)
arc.check_product()
arc.check_portal()
## Everything looks good!
## Load arcpy
arcpy = import('arcpy')
arcpy$env$overwriteOutput = TRUE
## ArcGIS Pro project
aprx = arcpy$mp$ArcGISProject('C:/Users/Documents/ArcGIS/Projects/SharingWebLayers/SharingWebLayers.aprx')
## Reference map object
m = aprx$listMaps('Map')[[1]]
## use getDefinition to get the CIM
m_cim = m$getDefinition('v3')
m_cim$useServiceLayerIDs = TRUE
m$setDefinition(m_cim)
aprx$save()
## add data
m$addDataFromPath(file.path(geodatabase_path, layer_name))
## layer
lyr = m$listLayers(layer_name)[[1]]
## checks on the layer
lyr$definitionQuery # ""
lyr$name == layer_name # TRUE
lyr$isFeatureLayer # TRUE
lyr$isGroupLayer # FALSE
## create sddraft
server_type = 'HOSTING_SERVER'
service_type = 'FEATURE'
service_name = 'SERVICE_TEST'
sddraft = m$getWebLayerSharingDraft(server_type, service_type, service_name, layers_and_tables = lyr)
sddraft$summary = "Testing the API"
sddraft$tags = "test"
## export
sddraft$exportToSDDraft(here::here('data', 'SERVICE_TEST.sddraft'))
## stage
arcpy$StageService_server(
in_service_definition_draft = here::here('data', 'SERVICE_TEST.sddraft'),
out_service_definition = here::here('data', 'SERVICE_TEST.sd'),
staging_version = 102
)
But I keep get the following error and I cannot figure it out,
Error in py_call_impl(callable, call_args$unnamed, call_args$named) : arcgisscripting.ExecuteError: ERROR 001272: Analyzer errors were encountered ([{"code":"00102","message":"Selected layer does not contain a required layer type for web feature layer","object":"Map"}]). Failed to execute (StageService).
-
1You had a tag for R but although you mention it in your body you do not say how it is relevant to your question so I removed it.PolyGeo– PolyGeo ♦2025年07月08日 19:28:54 +00:00Commented Jul 8 at 19:28
-
I'm not familiar with this R / reticulate code syntax. Why not write it in python as the tools were designed for that language so you can at least dismiss that its not some weird compatibility issue?Hornbydd– Hornbydd2025年07月08日 22:42:16 +00:00Commented Jul 8 at 22:42
1 Answer 1
It turns out that you need to save before staging,
aprx$save()
Then it worked.