There is a requirement to find the changes posted to default in GIS daily and send the changes to a Work Management System. We are working with Utility Network and using ArcGIS Pro 3.3.7. The UN is branch versioned and we are planning to write a python code to achieve this. We also planned to create a version under Default, find the difference between the Default and the new branch version, send the differences to WMS.
The version changes API only provides the changes in the branch version. Is there a way I can identify what has been changed in the Default (posted from other versions)?
I don't think you can get changes between the default and the newly created branch for your requirement.
You can try calculating moment-based differences by providing the timestamps.
For example, if you run today at 6 AM, you can get from yesterday's 6 AM to today's 6 AM.
current_moment = int(time.time() * 1000)
last_run_moment = current_moment - (24 * 60 * 60 * 1000)
import requests
import json
import time
# Configuration
portal_url = "https://yourserver.domain.com/portal"
fs_url = "https://yourserver.domain.com/server/rest/services/UtilityNetworkName/FeatureServer"
vms_url = f"{fs_url}/VersionManagementServer"
# Get Token (Ensure you use a service account with access)
token = "YOUR_TOKEN"
# Define your window (Unix Timestamps in milliseconds)
# Example: 24 hours ago until now
current_moment = int(time.time() * 1000)
last_run_moment = current_moment - (24 * 60 * 60 * 1000)
# Call the 'difference' endpoint on the DEFAULT version
# Note: 'sde.DEFAULT' usually has a constant GUID or can be targeted by name
diff_url = f"{vms_url}/versions/sde.DEFAULT/difference"
params = {
"f": "json",
"token": token,
"fromMoment": last_run_moment,
"toMoment": current_moment,
"layers": "[0,1,2,3]", # Array of Layer IDs in your UN Feature Service
"resultType": "objectIds" # Can also use 'features' for full geometry/attributes
}
response = requests.get(diff_url, params=params)
diff_data = response.json()
# Process the results for your WMS
# diff_data will contain 'inserts', 'updates', and 'deletes' categorized by Layer ID
I haven't tested this python code, but it should give you some idea. Please try and let me know.
@VenkataKondepati has the right idea. You can retrieve the differences directly from the default version for any two arbitrary moments in time. This ability was added in 10.9 when we introduced the fromMoment parameter (Differences | ArcGIS REST APIs | Esri Developer).
However, I can see a few problems with the code he generated:
It is using the wrong operation to calculate the differences. The operation should be differences (plural) not difference (singular).
The second problem is that you must always reference the global id of the version. You cannot use the name of the version in the URL. This means you'll need to query the version management service to get the global id of the default version and use that in your URL.
I'm not 100% sure about the way the moment is being calculated either.
In terms of writing your own code, while you can write raw HTTPS requests to do this, there is an API available for this via the ArcGIS API for Python: https://developers.arcgis.com/python/latest/api-reference/arcgis.features.managers.html#version
Hi @RobertKrisher,
Good catch. Thanks for the clarification.