Select to view content in your preferred language

Trigger Python Script After AGOL Hosted Feature Layer is Edited

47
3
yesterday
BethNewhartGE
Emerging Contributor

I was wondering if there was a way to trigger a Python script after a hosted feature layer is edited. Right now, the Python script runs every 15 minutes on Task Scheduler. This works fine, but seems excessive as the script really only needs to run after the hosted feature layer is edited. TIA.

0 Kudos
3 Replies
ChristopherCounsell
MVP Regular Contributor

ArcGIS Notebook server allows for this using feature service webhooks and python in an ArcGIS Notebook.

https://developers.arcgis.com/rest/enterprise-administration/notebook/execute-notebook/

Unfortunately the execute notebook API is only available in ArcGIS Enterprise, and not ArcGIS online. We are relegated to scheduled runs in agol hosted notebooks.

It should be similar for task scheduler. Options scheduling, but to allow for an external process to invoke a local python script... Seems problematic.

0 Kudos
MobiusSnake
MVP Regular Contributor

Do your edits require ArcPy, or can they be done using the ArcGIS API for Python?  If it's the latter you could create a serverless function (AWS Lambda, Azure Functions, etc.) and put the editing script in it, then have a webhook call it.  If I remember correctly the webhook should pass a token that the serverless function can use for authentication when calling edit_features.

If you aren't already doing this, you could minimize the amount of editing your notebook is doing using timestamps and edit tracking:

  • Create a hosted feature table with a single row and a single attributes, a "last notebook call" date/time value, and set it to some time in the past like 1/1/2025.
  • Enable edit tracking on features.
  • When the scheduled task runs, capture the current time (let's call this "Time A").
  • Query for features with 'last updated' values more recent than your last notebook call.  Only apply edits to those features.
  • Update your "last notebook call" value to the "Time A" value captured earlier.
0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Like the others have said, there isn't a way to automatically trigger a python script whenever certain edit criteria is met. However, with the release of power automate for arcgis there could be potential for some kind of automated trigger event to execute the script. I would need to dig in deeper to find if there is such a thing. 

0 Kudos