You can automate sharing and updating web layers with Python by using a combination of ArcPy functions and geoprocessing tools in the Publishing toolset.
Automate sharing a web layer
The workflow to publish or overwrite a web layer is similar. It begins with a map in a project that you want to share.
- First, create a service definition draft using the getWebLayerSharingDraft function from the Map class.
- Next, use the Stage Service geoprocessing tool to stage the service definition. Staging takes the service definition draft and consolidates all the information needed to share the web layer into a complete service definition.
- Finally, use the Upload Service Definition geoprocessing tool to upload the service definition and publish the web layer.
You may also want to automate replacing a web layer. To do this, use the Replace Web Layer geoprocessing tool in Python.
You will need to sign in to ArcGIS Pro with an ArcGIS Online or ArcGIS Enterprise account that has privileges to create content and publish.