Explore the options on publish and content for more fine grain control on your update process.Ĭommenting is not enabled for this article. The ArcGIS API for Python provides many options and settings for working with your hosted content.
If either of these items are missing, you’ll need to publish a web map from ArcGIS Pro independent of this script before implementing the update workflow.
If you’re working in a project with more than one map, update the Python code or create a new project with only the map you wish to share. The Python script assumes the first map found within a project will be the one to publish.The script uses arcpy to create and stage the data to be published. The Python script needs to be run on a machine with a valid ArcGIS Pro license.This blog has more information about creating a scheduled task. Once you’re sure the script has properly updated your hosted feature service, you can use the command in a scheduled task. You can run the code from command line with the following command.Ĭ:Program FilesArcGISProbinPythonenvsarcgispro-p圓python.exe c:mycodeupdatewebmap.py
Print(“Search for original SD on portal…”) # Find the SD, update it, publish /w overwrite and set sharing and metadata Sd = os.path.join(relPath, “WebUpdate.sd”)Īrcpy.mp.CreateWebLayerSDDraft(mp, sddraft, sd_fs_name, ‘MY_HOSTED_SERVICES’, ‘FEATURE_ACCESS’,”, True, True) Sddraft = os.path.join(relPath, “WebUpdate.sddraft”) # Local paths to create temporary content Portal = “” # Can also reference a local portal # Feature service/SD name in, user/password of the owner account # Update the following variables to match: PrjPath = r”C:PROJECTSNightlyUpdatesNightlyUpdates.aprx” A number of variables will need to be set within the script the path to the project, service name username, password, metadata and sharing options when you create the file. sd file and upload/publishes it on ArcGIS online. sd file with your new data will be uploaded to ArcGIS online where it will be used to replace the hosted service.Ĭopy the following code and save it locally as a Python file (updatewebmap.py). At a prescribed time, perhaps every night at midnight, the local. The source documents and data will be used to create a service definition (.sd) file using Python. Typically, this will involve one or more authors working on the local datasets that were shared to ArcGIS online. Alternatively, open a Python command prompt from: Start > ArcGIS > ArcGIS Pro > Python Command Prompt and use the following command, agreeing to update packages (if necessary):Īfter installing the ArcGIS Python API you need to define the steps of your update process. The first step is to install the ArcGIS API for Python from within ArcGIS Pro, find and add the arcgis package using the Python Package Manager. Investigate your hosted content and be certain of the service definition (.sd) and feature layer names before proceeding. When publishing a web map from ArcGIS Pro, the underlying feature layers may have _WFL1 appended to the name to ensure they are unique within organization. You’ll need to make note of the user name and password of the publisher account, the service name as well as the original project file (.aprx). This post assumes you’ve already shared a web map from ArcGIS Pro to ArcGIS online. In the spirit of this incredibly popular workflow to schedule updates, this blog will provide simpler Python code to update services using ArcGIS Pro 1.4 and the new ArcGIS API for Python. One method is well defined using ArcMap you select the option to overwrite the hosted feature layers when publishing your updates back to ArcGIS online. In 2013 and 2014 we explained how you could update your hosted feature services automatically, at a prescribed time, using Python. Many organizations share public maps on ArcGIS online and have defined a process to update and synchronize the feature layers from their local data.