Automate sharing web layers

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.

  1. First, create a service definition draft using the getWebLayerSharingDraft function from the Map class.

    To overwrite a web layer, modify the overwriteExistingService property of the sharing draft. For more information, see FeatureSharingDraft or MapImageSharingDraft.

  2. 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.
  3. 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.

  4. Note:

    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.

Learn more about sharing with ArcPy

Learn more about using tools in Python