Is it possible to have an email sent (to a list of recipients) whenever a point is added to a hosted File GDB on a public web-app?
The idea is to originate a permit application process from a web-map/app: applicants can add a point for the location they need a permit for, enter their information and apply for a permit (of particular kind). An email alerts officials that a permit has been applied for. The rest of the approval process flow from there and the hosted data is used to collect applicant information (including location for permit) as well as flag the status of the application as it makes its way through various stages of the approval process.
Any ideas on how to have edits trigger emails?
Solved! Go to Solution.
I'm not sure what's happening with this service. When I try and query it, and include to return all the fields, only the 'OBJECTID' field is returned:
URL = 'http://sig.versaillesgrandparc.fr/arcgis/rest/services/Hosted/Nicolli_Rapports/FeatureServer/0/query'
params = {'f': 'json', 'where': "1=1", 'outfields' : '*'}
req = urllib2.Request(URL, urllib.urlencode(params))
response = urllib2.urlopen(req)
data = json.load(response)
for feat in data['features']:
print feat['attributes']
I would test the above script on other services to see if other fields are returned other than just the 'objectid'.
Yes, I saw that on Fiddler 😕
But I get the created_date attributes when I'm doing the query manually on the Sharing/Rest
Maybe could I have more chance working directly with Querys from sharing/rest like
http://sig.versaillesgrandparc.fr/arcgis/rest/services/Hosted/Rapports_Nicollin/FeatureServer/0/quer...
Thanks for your time, I will try to understand how to make python working with that
This is exactly what I'm looking for, thank you for this script. However I get a KeyError 'features' in line 11. Is this a field from example feature class?
d_visca, 'features' is a key returned from the JSON of the feature service. This key is returned for all feature services. Do you have editor tracking enabled? The code queries for fields OBJECTID and created_date. If these do not exist, this may be the reason you are receiving this error.
I have the fields OBJECTID and CreationDate, so I changed create_date to my field name. I also activated the editor tracking but I still geht the same KeyError: 'features'. Maybe the problem is my URL, because it is a secure feature layer? I use the token as URL parameter like this:
http://server.arcgis.com/####/arcgis/rest/services/####/FeatureServer/0?token=####/query'
Maybe this is twisting everything up?
So my feature layer does not have any key named "features" or "attributes". I have keys like 'types', 'templates' and 'indexes'...
Sounds like the issue is your URL.
Make sure you are not just using the rest endpoint service URL, but have the query JSON page ".../FeatureServer/0/query'" ending of the URL. I had the same issue with a publicly shared HFS and needed to add "/0/query" to the end of my URL
Hi Jake,
I came across your post while searching for email alert for data change, and I found it interesting. I tried to use your code as is with my hosted Feature Service link, but still getting the error: KeyError: 'features'. Someone has reported the same error above. I have both the OBJECTID and create_date fields. Any idea why I'm getting the error. Thanks for your help in advance.
Daniel
Hi Daniel,
You will need to generate a token if your feature service is not shared with 'Everyone'. Try the following:
import urllib2, json, urllib, datetime, time, smtplib
from datetime import timedelta
oidList = []
username = 'jskinner_CountySandbox'
password = '********'
try:
print('Generating Token')
tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com'}
req = urllib2.Request(tokenURL, urllib.urlencode(params))
response = urllib2.urlopen(req)
data = json.load(response)
token = data['token']
except:
token = ''
URL = 'http://services.arcgis.com/dlFJXQQtlWFB4qUk/arcgis/rest/services/PropDamage/FeatureServer/0/query'
params = {'f': 'pjson', 'where': "1=1", 'outfields' : 'OBJECTID, created_date', 'returnGeometry' : 'false', 'token' : token}
req = urllib2.Request(URL, urllib.urlencode(params))
response = urllib2.urlopen(req)
data = json.load(response)
for feat in data['features']:
createDate = feat['attributes']['created_date']
createDate = int(str(createDate)[0:-3])
t = datetime.datetime.now() - timedelta(hours=1)
t = time.mktime(t.timetuple())
if createDate > t:
oidList.append(feat['attributes']['OBJECTID'])
print oidList
FROM = 'sender@hotmail.com'
TO = ['receiver@yahoo.com']
SUBJECT = 'New Feature Added'
TEXT = "Features with OBJECTIDs " + str(oidList) + " were added."
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
smtpObj = smtplib.SMTP(host='smtp.hotmail.com', port=25)
smtpObj.sendmail(FROM, TO, message)
print "Successfully sent email"
smtpObj.quit()