MikeyNeedHelp
MikeyNeedHelp

Reputation: 49

How to Update a Feature Layer using ArcGIS rest API in python (post request)

why this is not working ArcGIS Rest API, what am i doing wrong?

im trying to update a feature layer inside of a MapServer, i have 3 feature layers inside, avaliable at the id 0 1 and 3, im trying to change a value in one of the polygons i have, which has the Muni key and value, i thought i was doing alright, yet i didnt and i failed unfo, didnt work, does anyone know what the deal is with the UpdateFeatures?

url = 'https://server-url/arcgis/rest/services/TEMP/Miki_Test/MapServer/3/updateFeatures'

# Sample feature update payload (replace with actual updates)
updates = json.dumps([{
    "attributes": {
        "OBJECTID": 1,  # Use the actual OBJECTID of the feature you want to update
        "Muni": "דאדי"  # Replace 'FieldName' and 'NewValue' with actual field names and values
    }
}])

# Parameters for the update
params = {
    "f": "json",
    "updates": updates,
    "token": "valid token"
}

response = requests.post(url, data=params)

Upvotes: 1

Views: 568

Answers (1)

sandeman_13
sandeman_13

Reputation: 386

First, I would strongly recommend using the ArcGIS API for Python (i.e. arcgis package) instead of constructing your own POST requests to the layer. Here's what your code would look like using arcgis:

from getpass import getpass
from arcgis.gis import GIS
from arcgis.features import FeatureLayer

gis = GIS("<portal_url>", "<username>", getpass())
fl = FeatureLayer("https://server-url/arcgis/rest/services/TEMP/Miki_Test/MapServer/3")

updates = [{"attributes": {"OBJECTID": 1, "Muni": "דאדי"}]

fl.edit_features(updates=updates)

Note: there are various authentication methods, getpass() is just used as an example.

If you're set on constructing your own POST request using requests instead of arcgis, take a look at the ArcGIS REST API's documentation for the updateFeatures operation. You'll see that the updates key in your current code's params dictionary should be features.

Upvotes: 1

Related Questions