According to the documentation for arcpy.mp.CreateSharingDraft()
, the argument draft_value
can be
A Map, Layer or list of layers. You can use a subset of layers from a map to publish.
Passing a map object or a single layer object works as expected. However, I get an error if I try to pass a list of layers (or a subset of layers).
service = "MapServiceDraftExample"
aprx = arcpy.mp.ArcGISProject("MyProject.aprx"))
m = aprx.listMaps("MyMap")[0]
layers = m.layerList()
# works
service_draft = arcpy.sharing.CreateSharingDraft(
"STANDALONE_SERVER",
"MAP_SERVICE",
service,
m
)
# also works
service_draft = arcpy.sharing.CreateSharingDraft(
"STANDALONE_SERVER",
"MAP_SERVICE",
service,
layers[0]
)
# does not work
service_draft = arcpy.sharing.CreateSharingDraft(
"STANDALONE_SERVER",
"MAP_SERVICE",
service,
layers
)
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sharing.py", line 100, in CreateSharingDraft
map_service.draftValue = draft_value._arc_object #todo: temp fix
AttributeError: 'list' object has no attribute '_arc_object'
Am I misunderstanding the documentation or is there some other type of "layer list" object that is expected here?