I have also been experimenting with the REST API ApplyEdits function. In my case, it is with AGOL, so you will need to modify the URLs in the example. Updates are sent as a list of dictionaries. Here's a code sample.
import urllib, urllib2, json, sys, collections
# get a token - this is for AGOL, modify for portal/server
username = 'xxx'
password = 'yyy'
referer = "http://www.arcgis.com/"
tokenurl = "https://www.arcgis.com/sharing/rest/generateToken"
query_dict = { 'username': username, 'password': password, 'referer': referer }
query_string = urllib.urlencode(query_dict)
token = json.loads(urllib.urlopen(tokenurl + "?f=json", query_string).read())
if "token" not in token:
print(token['error'])
sys.exit(1)
# items to update, based on OBJECTID
# OBJECTID, POINT_X, POINT_Y, City
to_update = [
[ 11, -16683056.055, 8668941.2456, 'Anchorage' ],
[ 12, -16188891.9816, 8873309.4627000019, 'Glennallen' ],
[ 13, -16682516.0441, 8661113.2519000024, 'Anchorage' ]
]
updates = [] # this will be a list of dictionaries
for item in to_update
dict = {
'geometry' : {
'x' : item[1],
'y' : item[2]},
'attributes' : {
'OBJECTID' : item[0],
'City' : item[3]
}
}
updates.append(dict)
# modify URL for your needs
URL = "https://services2.arcgis.com/<directory>/arcgis/rest/services/<layer>/FeatureServer/0/applyEdits"
query_dict = {
"updates" : updates,
"f": "json",
"token": token['token']
}
jsonResponse = urllib.urlopen(URL, urllib.urlencode(query_dict))
response = json.loads(jsonResponse.read(),
object_pairs_hook=collections.OrderedDict)
print json.dumps(response, indent=4, sort_keys=False) # formatted json of response
If you do not need to update geometry, you can delete lines 28-30 and modify the to_update list and indexing.
For additions, the query_dict would contain the "adds" parameter which is a list of dictionaries similar to the "updates" parameter. Features to be added should include the geometry.
Additional documentation on ApplyEdits
#arcgis online rest api