ccabanero

executing addFeatures operation programmatically using REST API and JavaScript

Discussion created by ccabanero on Jul 24, 2013
Hello all, thanks for your time.

Context:
I have an ArcGIS Server 10.1 Enterprise Advanced instance on Windows 2008 Server R2. 
I have data in an Enterprise SDE Geodatabase on SQL Server.
I have successfully published a Feature Service with editing capabilities.  I confirm that I can edit the feature service because when I go to http://myserver/arcgis/rest/services/myservice/FeatureServer/0/addFeatures,  I can successfully add a feature by typing in an array of json objects into the 'features' text box of the Esri REST API web app.

What I'm Having Trouble Doing:
I now want to execute the addFeatures operation against my FeatureService using the REST API - but do it programmatically with JavaScript and jQuery.  I am aware that I can do such using the Esri JavaScript API methods - but in this case there is no map - thus, just using the REST API to edit data.

Here is my code ...

var theData = [
            {
                "geometry": {
                    "x": -13316097.345,
                    "y": 5861939.546999998
                },
                "attributes": {
                    "Column1": "Value1",
                    "Column2": "Value2"
                }
            }
        ];


       $.ajax({
            url: "http://myhostname/arcgis/rest/services/myservice/FeatureServer/0/addFeatures",
            dataType: 'json',
            type: 'POST',
            data: theData,
            success: function (data, textStatus, jqXHR) {

                //
                console.log('success');
                console.log(data);
                console.log(textStatus);
                console.log(jqXHR)
            },
            error: function (jqXHR, textStatus, errorThrown) {

                //
                console.log('error'); //<-- the response lands here ...
                console.log(jqXHR); //<-- the console logs the object
                console.log(textStatus); //<-- the console logs 'parsererror'
                console.log(errorThrown); //< -- the console logs 'SyntaxError {}'
            },
            complete: function (jqXHR, textStatus) {

                //
                console.log('complete');
                console.log(jqXHR);
                console.log(textStatus);
            }
        });


    
As you can see, the response I get from the GIS server is 'parse error'.  I believe this to potentially mean that the data that I am sending with my POST request is malformed? 

Questions:
1.What is the proper format/structure for the data in my POST request to my editable feature service?  Is my data structure wrong?  This is the same structure used when manually entering into the Esri REST API out-of-the-box web app.
2. Anyone else see anything incorrect about this $.ajax() call?

Thank you!!!

Outcomes