Select to view content in your preferred language

"Overwrite" existing hosted Feature Service (AGOL)

7150
6
Jump to solution
04-06-2015 01:51 PM
JamesCrandall
MVP Frequent Contributor

The only example I can locate has to do with publishing/overwriting a Feature Service on ArcGIS Online via creating and pushing an SDDraft from an .mxd document.  http://blogs.esri.com/esri/arcgis/2014/01/24/updating-your-hosted-feature-service-for-10-2/

I don't have an .mxd, I just have a File Geodatabase that I want to overwrite with.

I can:

1. Login

2. Access the Feature Service

Is there anyway to overwrite it when I grab that FS or am I just going to need to go the SDDraft route?

Thanks!

def findItem(sTitle, itemType, token):
    item = -1
    params = {'token': token, 'q': sTitle, 'f': 'json'}
    dat2 = urllib.urlencode(params)
    url = urljoin(AGOL, 'sharing/rest/search')
    r = urllib2.urlopen(url=url, data=dat2)

    if itemType is None:
        itemTypes = AGOLItemTypes
    else:
        itemTypes = [itemType]
    data = json.loads(r.read().decode('utf-8'))
    if len(data['results']) > 0:
        item = [item for item in data['results'] if item['title'] == sTitle and item['type'] in itemTypes][0]
   
    return item

def main():
    
    AGOLUser = username
    AGOLPassword = password
    token = gentoken(AGOLUser, AGOLPassword, 60)
    orgId = getOrganizationId(token)

    item = findItem('Name of Feature Service', 'Feature Service', token)
    if item is not None:
        print "item found"
        #I can see that I have grabbed the FS here
1 Solution

Accepted Solutions
JamesCrandall
MVP Frequent Contributor

Melissa,

This issue has been resolved.  A couple of things to look into (there doesn't appear to be a single issue associated with this problem).

1. You must use an .mxd to reference for creating the .sd an d.sddraft documents.

2. You must use the actual .mxd used in the original publishing event to AGOL.

3. The script/codebase should reference the .mxd saved on C:\ somewhere.

One or a combination of these three items allowed us to successfully "Overwrite" an existing hosted Feature Service on our enterprise AGOL.

Hope that helps!

View solution in original post

6 Replies
KevinBell
Deactivated User

I overwrite filegdb's without overwriting the entire service, if that's what you need.  I just (programmatically) shut the service down, overwrite, and start back up.

0 Kudos
JamesCrandall
MVP Frequent Contributor

You shut down ArcGIS Online?

I have a FGDB that I re-build, then upload ("overwrite") to a Feature Service in an Organizational account on ArcGIS Online by zipping up the .gdb first, login and go to the hosted FS, then click "Overwrite" (choosing the zipped .gdb with updates).  I don't use an .mxd anywhere and I hoped to just perform this with python.

Thanks

0 Kudos
JamesCrandall
MVP Frequent Contributor

It makes it all the way up to the point of creating the .sd file in the arcpy.StageService_server of the sddraft document.  I get:

ExecuteError: ERROR 001270: Consolidating the data failed.

Using the source code found here Updating your hosted feature service for 10.2 | ArcGIS Blog  and my settings.ini is correct.  Am able to connect, get the Feature Service id, etc... it just cannot create the .sd doc.

Any input is appreciated!

Complete error:

Traceback (most recent call last):

  File "C:\Python27\ArcGISx6410.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript

    exec codeObject in __main__.__dict__

  File "\\AGOL\py\update.py", line 292, in <module>

    makeSD(MXD, serviceName, tempDir, finalSD, maxRecords)

  File "\\AGOL\py\update.py", line 146, in makeSD

    arcpy.StageService_server(newSDdraft, outputSD)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\server.py", line 1204, in StageService

    raise e

ExecuteError: ERROR 001270: Consolidating the data failed.

0 Kudos
MelissaNorthey
Frequent Contributor

I wish I had the answer to this, but I stumbled upon this thread looking for the very same thing.  I have 21 non-spatial tables that I share via a zipped FGDB and it works beautifully with our Open Data page, however I want to automate the process so updates can happen weekly without me pushing the buttons.  I cannot go the MXD route as I have no spatial data in with the tables.  I tried creating a SD file, however that errored when I tried uploading that to ArcGIS Online saying that it wouldn't work with ArcGIS Online.  Frustrating, but there's got to be a way.

JamesCrandall
MVP Frequent Contributor

Melissa,

This issue has been resolved.  A couple of things to look into (there doesn't appear to be a single issue associated with this problem).

1. You must use an .mxd to reference for creating the .sd an d.sddraft documents.

2. You must use the actual .mxd used in the original publishing event to AGOL.

3. The script/codebase should reference the .mxd saved on C:\ somewhere.

One or a combination of these three items allowed us to successfully "Overwrite" an existing hosted Feature Service on our enterprise AGOL.

Hope that helps!

LeoLadefian4
Deactivated User

I've been using the blog script for 10.1, but all it really does it overwrite the service definition file in Arcgisonline.  Anyone successfully get it to overwrite the service? feature service?

Updating ArcGIS.com Hosted Feature Services with Python | ArcGIS Blog

0 Kudos