Updating your hosted feature service for 10.2

In April 2013, we explained how you could use a Python script to automate the publishing and overwriting of your feature service on ArcGIS.com. This post explains how to perform that same workflow using ArcGIS 10.2 or 10.2.1. The following instructions will get you started, or, scroll to the bottom of this post for extra information on what’s changed at 10.2.

Download the code and set the feature service properties

  1. Download the Python code (update.py) and settings.ini files in a zip by clicking here. You can check out the the repository on GitHub here.
  2. Extract the files to a working directory on your machine.
  3. Download and install the 3rd party module for Python called requests. Requests is used to upload the service definition (.SD) to your ArcGIS.com space. The request module can be downloaded as a zip file here. (Or you can see the full repository on GitHub here.) Inside the zip you’ll find a folder called requests under the master folder. Save the request folder and its contents to the same folder you previously extracted the .py and .ini to. Alternatively you can deploy requests to your local Python installation. Typically ArcGIS installs Python to C:\Python27\ArcGIS10.2\Lib\site-packages.
  4. Modify the settings.ini with the values specific to your service you’re updating. Make sure to keep the (left side) keywords in capital letters, and do not put quotes around the (right side) properties. The below graphic demonstrates how to set properties. Note, the code searches ArcGIS.com based on the username and service name. If the properties inside the settings.ini file do not match what is on ArcGIS.com, the script will fail to update your service.
  5. Run the update.py script. For example at command prompt you would run it like this: c:\>c:\Python27\ArcGIS10.2\python.exe c:\myLocalDirectory\update.py

This help link explains how to automatically run a Python script as a scheduled task in Windows. You could set your task to run every night at midnight to ensure ArcGIS.com always has your most up to date features.

Please note these scripts are not supported by Esri Technical Support. Questions should be directed towards either the Python or the ArcGIS Online User Forum.

Extra Information

The authentication mechanism of ArcGIS 10.2 was upgraded to the industry standard of OAuth2. The SignInToPortal tool is no longer used to authenticate  with ArcGIS.com (this was the method used in the previous blog post). This new workflow authenticates directly with the ArcGIS.com REST API. The SD file is uploaded and REST calls are made to ArcGIS.com to delete the existing service, and publish the uploaded SD file.

An issue was also identified in 10.2 where some people had problems overwriting their feature service due to bug NIM095154. This issue has been resolved with the release of 10.2.1.

Note, using this overwrite-publish method, the feature service will be assigned a new item ID. The existing service is deleted and this new one with the same name is published. Any client that uses the full URL to the service will continue to work. A client which consumed a feature service via the item ID will need to be updated. WebMaps may have to be updated depending how the feature service was added to the map (full URL or item ID).

Improve the workflow

If you have a code suggestion, just fork it on GitHub, and make a pull request. We’ll review and patch as necessary.

This entry was posted in Analysis & Geoprocessing, ArcGIS Online, Python, Services and tagged , , , , . Bookmark the permalink.

Leave a Reply

4 Comments

  1. julianinskip says:

    Great, tool, thanks.

    I seem to have an issue though if my feature service is in a folder on AGOL.
    “.sd file not uploaded. Check the errors and try again.
    {u’error’: {u’messageCode’: u’CONT_0005′, u’message’: u’Item does not exist in this folder.’, u’code’: 400, u’details’: []}}”

    I have tried “FOLDERNAME\\SERVICENAME”, “FOLDERNAME\SERVICENAME” and “FOLDERNAME/SERVICENAME”, all of which give me another error:
    “Could not find a service to update. Check the service name in the settings.ini”

    It works great when my service is not in a folder.

  2. cdaniel says:

    In settings.ini “GROUPS” appears to not be working. I am using the group “Title” or name, but the documentation above refers to a group “ID”. I looked my group in the AGO administrator and there doesn’t not appear to be an “ID” for the group other than it’s “title/name”. Other than it appears to be working fine.

  3. cdaniel says:

    I found a simple way to find a group ID. Login to AGO. Click “My Organization” (top of the page). On the “My Organization” page, under “Featured Groups” (bottom right) click the group you are trying to find the ID of. In your browser’s address window you’ll find the ID in this format http://.maps.arcgis.com/home/group.html?groupid=id:.

    BTW – I tested this and using this ID works.

    PS – Thanks for the hint Kevin!