0

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

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 8 at 17:40
2
  • 1
    You 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. Commented 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? Commented Jul 8 at 22:42

1 Answer 1

0

It turns out that you need to save before staging,

aprx$save()

Then it worked.

answered Jul 10 at 18:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.