I am trying to automate some of the UN admin tasks using the Python API, but I am struggling a bit with this task, namely creating the UN object (and hitting the default version). Have either of @jclarke or @RobertKrisher had any success in developing this script? Below is what I have so far.
import arcgis
from arcgis.gis import GIS
gis = GIS('https://myorg.gov/portal/','username', 'password')
#utility network URL
util_url = 'https://myorg.gov/un_fabric/rest/services/Utility_Network/Water_Distribution_Source/UtilityNetworkServer'
network_url = 'https://myorg.gov/un_fabric/rest/services/Utility_Network/Water_Distribution_Source/FeatureServer/9'
UN_url = 'https://myorg.gov/un_fabric/rest/services/Utility_Network/Water_Distribution_Source/FeatureServer'
UN_vers = 'https://myorg.gov/un_fabric/rest/services/Utility_Network/Water_Distribution_Source/VersionManagementServer'
#--------------------------------------------------------
UN_flc = arcgis.features.layer.FeatureLayerCollection(UN_url,gis)
vms_from_flc = UN_flc.versions
default_version = vms_from_flc.all[0]
default_guid = default_version.properties.versionGuid
#---------------------------------------------------------
#returns error "AttributeError: 'PropertyMap' instance has no attribute 'versionName'"
df_version = arcgis.features._version.Version(url=UN_url,flc=UN_flc,gis=gis,session_guid=default_guid)
UN = arcgis.features._utility.UtilityNetworkManager(url=util_url,version=default_version,gis=gis)
envelope = {
"xmin": 1018472.222250,
"ymin": 1819952.386750,
"xmax": 1105416.666750,
"ymax": 1940603.168750,
"spatialReference": {
"wkid": 3435,
"latestWkid": 102671
}
}
#returns error "Exception: Unable to resume a service session."
UN.validate_topology(envelope)
#returns error "Exception: Unable to resume a service session."
UN.update_subnetwork('Water','Water System',all_subnetwork_tier=True,continue_on_failure=True)
UN.update_is_connected()