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).