Apply Edits (Feature Service)

Description

This operation is supported at 10.1 and later.

The applyEdits operation applies edits to features associated with multiple layers or tables in a single call (POST only). This operation is performed on a feature service resource. The result of this operation is an array of edit results for each layer/table edited. Each edit result identifies a single feature on a layer or table and indicates whether the edits were successful or not. If an edit is not successful, the edit result also includes an error code and an error description.

NoteNote:

Hosted feature services support adding or updating blob column values in Base64.

You can provide arguments to the applyEdits operation as defined in the following parameters table:

Request parameters

Parameter

Details

f

Description: The response format. The default response format is html.

Values: html | json

edits

Description: The array of layers and edits to be applied.

Features to be added or updated to a feature layer should include the geometry.

Records to be added or updated to a table should not include the geometry.

If useGlobalIds is true, the features are added while preserving their globalIds. For new features and attachments, the client must generate globalIds. In order for a feature or attachment to be updated or deleted, clients must include its globalId.

If useGlobalIds is false (default), globalIds submitted with the features are ignored and new globalids are assigned when features are added. In order for a feature to be updated or deleted, the attributes property of the feature must include the object ID of the feature along with the other attributes. Attachments are not supported as an edit payload when useGlobalIds is false.

"attributes" : {
  "OBJECTID" : 37,
  "OWNER" : "Joe Smith",
  "VALUE" : 94820.37,
  "APPROVED" : true,
  "LASTUPDATE" : 1227667627940
}

Syntax:

[
{ "id" : <layerId1>,
    "adds" : [<feature1>, <feature2>],
    "updates" : [<feature1>, <feature2>],
    "deletes" : [<objectID1>, <objectID2>]
},
{ "id" : <layerId2>,
    "adds" : [<feature1>, <feature2>],
    "updates" : [<feature1>, <feature2>],
    "deletes" : [<objectID1>, <objectID2>]
}  
]

Example:

[
    {
         "id" : 0,
        "adds" : [
            {
                "geometry" : {
    		     "x": -143.501,
    		     "y": 57.043000000000006
                },
                "attributes" : {
                    "datetime" : 1272210710000,
                    "depth" : 31.100000000000001,
                    "region" : "Andreanof Islands, Aleutian Islands, Alaska" 
                } 
            },
            {
                "geometry" : {
                    	"x" : -72.865099999999927,
                    "y" : -37.486599999999953 
                },
                "attributes" : {
                    "datetime" : 1272210142999,
                    "depth" : "40.x",
                    "region" : "Bio-Bio, Chile" 
                } 
            } 
        ],
         "updates" : [
            {
                "geometry" : {
                    "x" : -149.450,
                    "y" : 60.120 
                },
                "attributes" : {
                    "OBJECTID" : 50,
                    "datetime" : 1272210710000,
                    "region" : "Andreanof Islands, Aleutian Islands, Alaska" 
                } 
            } 
        ],
        "deletes" : [
            19,23 
        ] 
    },
    {
        "id" : 1,
        "deletes" : [
            34,44 
        ] 
    } 
]

Syntax (when useGlobalIds is true) :

[
{ "id" : <layerId1>,
    "adds" : [<feature1>, <feature2>],
    "updates" : [<feature1>, <feature2>],
    "deletes" : [<GlobalID1>, <GlobalID2>],
    "attachments": {
      "adds": [<attachment1>,  <attachment2>],
      "updates": [<attachment1>,  <attachment2>],
      "deletes": ["<attachmentGlobalId1>", "<attachmentGlobalId2>"]
    }
},
{ "id" : <layerId2>,
   ...
}  
]

Example (when useGlobalIds is true) :

[
    {
        "id": 0,
        "adds": [
            {
                "geometry": {
                    "x": -118.15,
                    "y": 33.8
                },
                "attributes": {
                    "OWNER": "Joe Smith",
                    "VALUE": 94820.37,
                    "APPROVED": true,
                    "LASTUPDATE": 1227663551096,
                    "GlobalID": "{74100804-E229-49b8-8CDC-9B5D3EF03EDA}"
                }
            },
            {
                "geometry": {
                    "x": -118.37,
                    "y": 34.086
                },
                "attributes": {
                    "OWNER": "John Doe",
                    "VALUE": 17325.9,
                    "APPROVED": false,
                    "LASTUPDATE": 1227628579430,
                    "GlobalID": "{39B856DC-AFE4-4c02-B433-A9361ACD91CF}"
                }
            }
        ],
        "updates": [
            {
                "geometry": {
                    "x": -118.15,
                    "y": 33.8
                },
                "attributes": {
                    "OBJECTID": 37,
                    "OWNER": "Joe Smith",
                    "VALUE": 94820.37,
                    "APPROVED": true,
                    "LASTUPDATE": 1227667627940,
                    "GlobalID": "{1A9F8368-F9BB-428B-BB03-F45724362DB5}"
                }
            },
            {
                "geometry": {
                    "x": -118.37,
                    "y": 34.086
                },
                "attributes": {
                    "OBJECTID": 462,
                    "OWNER": "John Doe",
                    "VALUE": 17325.9,
                    "APPROVED": false,
                    "LASTUPDATE": 9269154204840,
                    "GlobalID": "{6CE34136-EC3A-40D7-80BF-E1D9BE33812A}"
                }
            }
        ],
        "deletes": [
            "{0A196F7B-44A6-4EE8-94C0-4417EA3B0841}",
            "{C2746F2C-80E5-4506-B51F-3B7B134BC58B}"
        ],
        "attachments": {
            "adds": [
                {
                    "globalId": "{55E85F98-FBDD-4129-9F0B-848DD40BD911}",
                    "parentGlobalId": "{74100804-E229-49b8-8CDC-9B5D3EF03EDA}",
                    "contentType": "image/pjpeg",
                    "name": "Pothole.jpg",
                    "uploadId": "{DD1D0A30-CD6E-4ad7-A516-C2468FD95E5E}"
                },
                {
                    "globalId": "{3373EE9A-4619-41B7-918B-DB54575465BB}",
                    "parentGlobalId": "{39B856DC-AFE4-4c02-B433-A9361ACD91CF}",
                    "contentType": "image/pjpeg",
                    "name": "Debree.jpg",
                    "data": "<base 64 encoded data>"
                }
            ],
            "updates": [
                {
                    "globalId": "{8FDD9AEF-E05E-440A-9426-1D7F301E1EBA}",
                    "contentType": "image/pjpeg",
                    "name": "IllegalParking.jpg",
                    "uploadId": "{57860BE4-3B85-44DD-A0E7-BE252AC79061}"
                }
            ],
            "deletes": [
                "{95059311-741C-4596-88EF-C437C50F7C00}",
                "{18F43B1C-2754-4D05-BCB0-C4643C331C29}"
            ]
        }
    },
    {
        "id": 1,
        "deletes": [
            "{8BCB622B-E45D-4A09-8BAC-1D8735E9625F}",
            "{D44DFB67-C66B-45EA-B24C-FF4632C8081D}"
        ]
    }
]

gdbVersion

//This option was added at 10.1.

Description: Geodatabase version to apply the edits. This parameter applies only if the isDataVersioned property of the layer is true.

If the gdbVersion parameter is not specified, edits are made to the published map’s version.

Syntax: gdbVersion=<version>

Example: gdbVersion=SDE.DEFAULT

honorSequenceOfEdits

This option was added at 10.5 and works with ArcGIS Server services only.

Description: Optional parameter specifying whether to apply edits in the order they are submitted in the JSON. If honorSequenceOfEdits = true, edits will apply in the submitted order. If honorSequenceOfEdits = false, which is the default, edits will apply in ascending layer-ID order. All the edits for the layer with the lowest ID will apply first.

Values: true|false

returnEditMoment

This option was added at 10.5 and works with ArcGIS Server services only.

Description: Optional parameter specifying whether the response will report the time edits were applied. If returnEditMoment = true, the server will return the time edits were applied in the response's editMoment key.

Values: true|false

Example: returnEditMoment=true

rollbackOnFailure

//This option was added at 10.1.

Description: Optional parameter to specify if the edits should be applied only if all submitted edits succeed. If false, the server will apply the edits that succeed even if some of the submitted edits fail. If true, the server will apply the edits only if all edits succeed. The default value is true.

Not all data supports setting this parameter. Query the supportsRollbackonFailureParameter property of the layer to determine whether or not a layer supports setting this parameter. If supportsRollbackOnFailureParameter = false for a layer, then when editing this layer, rollbackOnFailure will always be true, regardless of how the parameter is set. However, if supportsRollbackonFailureParameter = true, this means the rollbackOnFailure parameter value will be honored on edit operations.

Values: true|false

Example: rollbackOnFailure=true

useGlobalIds

This option was added at 10.4

Description: Optional parameter which is false by default. Requires the service's supportsApplyEditsWithGlobalIds property to be true.

When set to true, the features and attachments in the adds, updates, deletes, attachments/adds, attachments/updates, and attachments/deletes for all the layers in the edits parameter are identified by their globalIds. When true, the service adds the new features and attachments while preserving the globalIds submitted in the payload. If the globalId of a feature (or an attachment) collides with a pre-existing feature (or an attachment), that feature and/or attachment add fails. Other adds, updates, or deletes are attempted if rollbackOnFailure is false. If rollbackOnFailure is true, the whole operation fails on any failure including a globalId collision.

When useGlobalIds is true, updates or deletes are identified by each feature or attachment globalId rather than their objectId or attachmentId.

Values: true|false

Example: useGlobalIds=true

trueCurveClient

This option was added at 10.5

Description: Optional parameter which is false by default is set by client to indicate to the server that client in true curve capable.

When set to true by client, indicates to the server that true curves geometries should be downloaded from and that geometries containing true curves should be consumed by the feature service, without converting curves to densified polylines or polygons.

When set to false by client, indicates to the server that client is not true curves capable and hence, curves are converted to densified polylines or polygons.

Values: true|false

Example: trueCurveClient=true

Example Usage

Example 1: Apply edits on a feature service resource:

http://services.myserver.com/lidGgNLxw9LL0SbI/ArcGIS/rest/services/PoolPermits/FeatureServer/applyEdits

Sample input for adds, represented by an array of features:

[
    {
        "id" : 0,
        "adds" : [
            {
                "geometry" : {
    		            "x": -143.501,
    		            "y": 57.043000000000006
                },
                "attributes" : {
                    "datetime" : 1272210710000,
                    "depth" : 31.100000000000001,
                    "region" : "Andreanof Islands, Aleutian Islands, Alaska" 
                } 
            },
            {
                "geometry" : {
                    	"x" : -72.865099999999927,
                    "y" : -37.486599999999953 
                },
                "attributes" : {
                    "datetime" : 1272210142999,
                    "depth" : "40.x",
                    "region" : "Bio-Bio, Chile" 
                } 
            } 
        ],
        "updates" : [
            {
                "geometry" : {
                    "x" : -149.450,
                    "y" : 60.120 
                },
                "attributes" : {
                    "OBJECTID" : 50,
                    "datetime" : 1272210710000,
                    "region" : "Andreanof Islands, Aleutian Islands, Alaska" 
                } 
            } 
        ],
        "deletes" : [
            19,23 
        ] 
    },
    {
        "id" : 1,
        "deletes" : [
            34,44 
        ] 
    } 
]

Example 2: Adding a feature and attachment in one call with useGlobalIds is true:

[
    {
        "id": 0,
        "adds": [
            {
                "geometry": {
                    "x": -118.15,
                    "y": 33.80
                },
                "attributes": {
                    "OWNER": "Joe Smith",
                    "GlobalID": "{74100804-E229-49b8-8CDC-9B5D3EF03EDA}",
                    "VALUE": 94820.37,
                    "APPROVED": true,
                    "LASTUPDATE": 1227663551096
                }
            }
        ],//endofadds"
        attachments": {
            "adds": [
                {
                    "globalId": "{55E85F98-FBDD-4129-9F0B-848DD40BD911}",
                    "parentGlobalId": "{74100804-E229-49b8-8CDC-9B5D3EF03EDA}",
                    "contentType": "image/pjpeg",
                    name":"Pothole.jpg",  
                   "uploadId" : {DD1D0A30-CD6E-4ad7-A516-C2468FD95E5E}"
                }
            ]//endofattachments/adds
        }//endofattachments
    }//endoflayer
]//endofedits

Response:

[
    {
        "id": 0,
        "addResults": [
            {
                "objectId": 1000,
                "globalId": "{74100804-E229-49b8-8CDC-9B5D3EF03EDA}",
                "success": true
            }
        ],
        "attachments": {
            "addResults": [
                {
                    "objectId": 2000,
                    "globalId": "{55E85F98-FBDD-4129-9F0B-848DD40BD911}",
                    "success": true
                }
            ]
        }
    }
]

Example 3: Adding features and a relationship between them in one call with useGlobalIds is true:

Let us assume the service has a Parcel layer (id: 0) and Owner table (id: 1). Parcel is the Origin Class and Owner is the Destination Class. The Parcel's globalID is related to Owner's parcelguid field, which makes parcelguid a foreign key field. An editor wants to add a parcel and an owner and have them related in one applyEdits call:

[
   {"id" : 0,
    "adds" : 
     [
       {"geometry" : <Parcel polygon geometry>,  
        "attributes" : {"Name" : "Donut Hole", 
	    "Neighborhood": "North Redlands",   
        "GlobalID": "{74100804-E229-49b8-8CDC-9B5D3EF03EDA}" 
                        }  
       }
    ],    
  }//end of layer 0
   {"id" : 1,
    "adds" : 
     [
       {
        "attributes" : {"Name" : "John Smith ", 
        "GlobalID": "{EFC28461-50EC-4193-82A8-7C46CF34E613}", 
        "ParcelGuid":"{74100804-E229-49b8-8CDC-9B5D3EF03EDA}" 
                      } 
       }
     ],    
 }//end of layer 1

The service will add a parcel to Parcel layer (id: 0) and an owner record to Owner table (id: 1). They will be related because of identical values for the parcel's globalID and the owner's parcelguid.

Response:

[
    {
        "id": 0,
        "addResults": [
            {
                "objectId": 2000,
                "globalId": "{74100804-E229-49b8-8CDC-9B5D3EF03EDA}",
                "success": true
            }
        ]
    },
    {
        "id": 1,
        "addResults": [
            {
                "objectId": 3000,
                "globalId": "{EFC28461-50EC-4193-82A8-7C46CF34E613}",
                "success": true
            }
        ]
    }
]

JSON response syntax

[
  {   
    "id" : <layerId1>,
    "addResults" : [
    {
      "objectId" : <objectId1>,
      "globalId" : <globalId1>,
      "success" : <true | false>,
      "error" : { //only if success is false
        "code" : <code1>,
        "description" : "<description1>",
      }
    },
    {
      "objectId" : <objectId2>,
      "globalId" : <globalId2>,
      "success" : <true | false>,
      "error" : { //only if success is false
        "code" : <code2>,
        "description" : "<description2>",
      }
    }
  ],
  "updateResults" : [
    {
      "objectId" : <objectId1>,
      "globalId" : <globalId1>,
      "success" : <true | false>,
      "error" : { //only if success is false
        "code" : <code1>,
        "description" : "<description1>",
      }
    },
    {
      "objectId" : <objectId2>,
      "globalId" : <globalId2>,
      "success" : <true | false>,
      "error" : { //only if success is false
        "code" : <code2>,
        "description" : "<description2>",
      }
    }
  ],
  "deleteResults" : [
    {
      "objectId" : <objectId1>,
      "globalId" : <globalId1>,
      "success" : <true | false>,
      "error" : { //only if success is false
        "code" : <code1>,
        "description" : "<description1>",
      }
    },
    {
      "objectId" : <objectId2>,
      "globalId" : <globalId2>,
      "success" : <true | false>,
      "error" : { //only if success is false
        "code" : <code2>,
        "description" : "<description2>",
      }
    }
  ],
  "attachments": {
    "addResults": [],
    "updateResults": [],
    "deleteResults": []
  },
},
{   
    "id" : <layerId2>,
    "addResults" : [
    {
      "objectId" : <objectId1>,
      "globalId" : <globalId1>,
      "success" : <true | false>,
      "error" : { //only if success is false
        "code" : <code1>,
        "description" : "<description1>",
      }
    },
    {
      "objectId" : <objectId2>,
      "globalId" : <globalId2>,
      "success" : <true | false>,
      "error" : { //only if success is false
        "code" : <code2>,
        "description" : "<description2>",
      }
    }
  ],
  "updateResults" : [
    {
      "objectId" : <objectId1>,
      "globalId" : <globalId1>,
      "success" : <true | false>,
      "error" : { //only if success is false
        "code" : <code1>,
        "description" : "<description1>",
      }
    },
    {
      "objectId" : <objectId2>,
      "globalId" : <globalId2>,
      "success" : <true | false>,
      "error" : { //only if success is false
        "code" : <code2>,
        "description" : "<description2>",
      }
    }
  ],
  "deleteResults" : [
    {
      "objectId" : <objectId1>,
      "globalId" : <globalId1>,
      "success" : <true | false>,
      "error" : { //only if success is false
        "code" : <code1>,
        "description" : "<description1>",
      }
    },
    {
      "objectId" : <objectId2>,
      "globalId" : <globalId2>,
      "success" : <true | false>,
      "error" : { //only if success is false
        "code" : <code2>,
        "description" : "<description2>",
      }
    }
  ],
  "attachments": {
    "addResults": [],
    "updateResults": [],
    "deleteResults": []
  },
}
]

JSON response example

[
 {
  "id": 0,
  "addResults": [
   {
    "objectId": 617,
    "globalId" : "{be6557a4-2204-4a66-a901-7295080003a6}",
    "success": true
   },
   {
    "success": false,
    "error": {
     "code": -2147217395,
     "description": "Setting of Value for depth failed."
    }
   }
  ],
  "updateResults": [
   {
    "objectId": 50,
    "globalId" : "{09b3b932-a75c-4438-837e-9a17f84113d5}",
    "success": true
   }
  ],
  "deleteResults": [
   {
    "objectId": 19,
    "success": true
   },
   {
    "objectId": 23,
    "success": true
   }
  ]
 },
 {
  "id": 1,
  "deleteResults": [
   {
    "objectId": 34,
    "success": true
   },
   {
    "objectId": 44,
    "success": true
   }
  ]
 }
]

JSON response example (where returnEditMoment and useGlobalids are true, and attachments are included)

[
    {
        "id": 0,
								"editMoment" : 1457994488000,
        "addResults": [
            {
                "objectId": 618,
                "globalId": "{74100804-E229-49b8-8CDC-9B5D3EF03EDA}",
                "success": true
            },
            {
                "objectId": 619,
                "globalId": "{39B856DC-AFE4-4c02-B433-A9361ACD91CF}",
                "success": true
            }
        ],
        "updateResults": [
            {
                "objectId": 50,
                "globalId": "{1A9F8368-F9BB-428B-BB03-F45724362DB5}",
                "success": true
            },
            {
                "objectId": 51,
                "globalId": "{6CE34136-EC3A-40D7-80BF-E1D9BE33812A}",
                "success": true
            }
        ],
        "deleteResults": [
            {
                "objectId": 25,
                "globalId": "{0A196F7B-44A6-4EE8-94C0-4417EA3B0841}",
                "success": true
            },
            {
                "objectId": 26,
                "globalId": "{C2746F2C-80E5-4506-B51F-3B7B134BC58B}",
                "success": true
            }
        ],
        "attachments": {
            "addResults": [
                {
                    "objectId": 500,
                    "globalId": "{55E85F98-FBDD-4129-9F0B-848DD40BD911}",
                    "success": true
                },
                {
                    "objectId": 501,
                    "globalId": "{3373EE9A-4619-41B7-918B-DB54575465BB}",
                    "success": true
                }
            ],
            "updateResults": [
                {
                    "objectId": 600,
                    "globalId": "{8FDD9AEF-E05E-440A-9426-1D7F301E1EBA}",
                    "success": true
                },
                {
                    "objectId": 600,
                    "globalId": "{6CE34136-EC3A-40D7-80BF-E1D9BE33812A}",
                    "success": true
                }
            ],
            "deleteResults": [
                {
                    "objectId": 800,
                    "globalId": "{95059311-741C-4596-88EF-C437C50F7C00}",
                    "success": true
                },
                {
                    "objectId": 801,
                    "globalId": " {18F43B1C-2754-4D05-BCB0-C4643C331C29}",
                    "success": true
                }
            ]
        }
    },
    {
        "id": 1,
								"editMoment" : 1457994488000,
        "deleteResults": [
            {
                "objectId": 25,
                "globalId": "{8BCB622B-E45D-4A09-8BAC-1D8735E9625F}",
                "success": true
            },
            {
                "objectId": 26,
                "globalId": "{D44DFB67-C66B-45EA-B24C-FF4632C8081D}",
                "success": true
            }
        ]
    }
]

7/5/2017