Select to view content in your preferred language

How to Automate Overwrite Web Layer to Publish Map Image Layer

85
3
Jump to solution
yesterday
Nryan
by
New Contributor

Hi! I have a Map Image Layer (MapServer) stored on our Portal. This needs to update weekly, so I'm trying to figure out how to update this using python. The tool I use to update is called "Overwrite Web Layer". Unfortunately, this is not a geoprocessing tool, so there is no python command.

I've tried exporting map to SD, and then using the SD to overwrite the map image server. That did not work. That code is below.

Any help would be greatly appreciated!

 

 

 

Tool.png

 

arcpy.server.UploadServiceDefinition(
    in_sd_file=r"T:\NRYANGISWKSP\Projects\OpenGov\_FINAL SCRIPT\OpenGov_MAT.sd",
    in_server="https://gis.cityofgoosecreek.com/arcgis",
    in_service_name="OpenGov_Map_Layers",
    in_cluster="",
    in_folder_type="FROM_SERVICE_DEFINITION",
    in_folder="",
    in_startupType="STARTED",
    in_override="USE_DEFINITION",
    in_my_contents="NO_SHARE_ONLINE",
    in_public="PRIVATE",
    in_organization="NO_SHARE_ORGANIZATION",
    in_groups=None,
    in_item_id=None
)

 

0 Kudos
1 Solution

Accepted Solutions
David_McRitchie
Esri Regular Contributor

Hey Nryan it would be worth trying the following sample. Let me know if you get stuck with it.

Hope that helps,

Esri UK -Technical Support Analyst

View solution in original post

3 Replies
David_McRitchie
Esri Regular Contributor

Hey Nryan it would be worth trying the following sample. Let me know if you get stuck with it.

Hope that helps,

Esri UK -Technical Support Analyst
Nryan
by
New Contributor

This worked perfectly, thank you!

0 Kudos
SimonP
by
Emerging Contributor

Hello, we have this process from saved SD files. I would recommend doing it with the Python API for ArcGIS rather than arcpy, as the code would be more portable since it would not require a license on the agent executing the code unlike arcpy. All the code needed to publish or stop the service is available in the Python API for ArcGIS. For example, we run our code in a DevOps pipeline on dynamically created agents without any Esri products installed locally on the agent.

basically it's just a few lines of code:

from arcgis.gis import GIS
from arcgis.gis.server import Server
gis = GIS(url=urlPortal, username=username, password=password)
serverManager = gis.admin.servers
federatedServer = next(serveur for serveur in serverManager.list() if serveur.url == f'{urlFederated}/admin')
succes = federatedServer.publish_sd(sd_file=sdFilePath, folder=serviceFolder)

 

0 Kudos