I would like to publish a table to our ArcGIS Online (AGOL) organization account.

Is it possible to consume hosted features in AGOL to a local db or ArcSDE database connection?

By consume I mean import a hosted ArcGIS Online table into a geodatabase with ArcPy.

By local db, I mean file geodatabase

  • 1
    By what do you mean "consume"? Any data can always be loaded in a myriad of ways, but some of those ways are easier than others. Please edit the question to expound on the desired process.
    – Vince
    Commented Apr 23, 2015 at 21:15
  • What do you mean by a "local db"? Do you mean a file geodatabase?
    – PolyGeo
    Commented Apr 27, 2015 at 3:45
  • @Geoffrey West: I got the same error. I think it is caused by an empty dataset.
    – user93959
    Commented Mar 22, 2017 at 15:52

2 Answers 2


Give a quick read of this blog. It lays the ground work for what you want to do. You just need to replace FeatureSet with RecordSet.

The following code uses a featureservice, and brings down the items as a table -- you keep saying table, so I assume you're talking items without geometry. If you actually mean features, change the returnGeo field to True, and then flip RecordSet to FeatureSet, and CopyRows to CopyFeatures

import arcpy

FSURL = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Military/FeatureServer/2/"

where = "1=1"
fields = "reinforced, speed, countrycode, staffcomment"
returnGeo = False
token = ''

query = "query?where={0}&outFields={1}&returnGeometry={2}&returnIdsOnly=false&returnCountOnly=false&f=json&token={3}".format(
where, fields, returnGeo, token)

url = FSURL + query
rs = arcpy.RecordSet()

arcpy.CopyRows_management(rs, r"c:\temp\f.gdb\fsTable")

Modify the query, where clause and fields to match what you want to copy local from your featureservice.

  • Kevin, will this work with the secured (non-public) AGOL hosted service? You need to provide username and password. I read that you can provide token, but how this token should be generated? Commented Apr 27, 2015 at 16:40
  • You'll have to obtain a token to work with a secured service. Theres a code example to obtain a token here: github.com/arcpy/AutomaticUpdatesIntoFeatureService/blob/master/…
    – KHibma
    Commented Apr 27, 2015 at 18:36
  • This is a good start, but based on network connectivity, this script must leverage AGOL, and not ArcGIS Server for a hosted table. The ideal workflow would to have a constituent enter a table each day and a script then consumes this AGOL hosted table into a local file geodatabase or ArcSDE database. Commented Apr 28, 2015 at 13:46
  • Its the same difference. Replace the URL in the code sample with the one to a hosted feature service on AGOL.
    – KHibma
    Commented Apr 28, 2015 at 14:34
  • I see, when I try this, this error returns. RuntimeError: RecordSetObject: Cannot open table for Load Commented Apr 28, 2015 at 16:09

@ Alex Tereshenkov

Please see this script which takes into account the token generation for AGOL hosted features.

import arcpy
import json
import urllib
import urllib2

gtUrl = 'https://www.arcgis.com/sharing/rest/generateToken'
gtValues = {'username' : 'yourUserName',
'password' : 'YourPassWord',
'referer' : 'http://www.arcgis.com',
'f' : 'json' }
gtData = urllib.urlencode(gtValues)
gtRequest = urllib2.Request(gtUrl, gtData)
gtResponse = urllib2.urlopen(gtRequest)
gtJson = json.load(gtResponse)
gtToken = gtJson['token']

FSURL = "http://services1.arcgis.com/X1hcdGx5Fxqn4d0j/ArcGIS/rest/services/aService/FeatureServer/0/"
#last back slash is necessary

where = "1=1"
returnGeo = False
token = gtToken

print token

query = "query?where={0}&outFields={1}&returnGeometry={2}&returnIdsOnly=false&returnCountOnly=false&f=json&token={3}".format(
where, fields, returnGeo, token)

url = FSURL + query

rs = arcpy.RecordSet()
arcpy.CopyRows_management(rs, r"c:\rest_test\rest_test.gdb\fsTable")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.