Why does the addFeatures json response not always include "addResults"[]?

311
0
04-15-2020 03:58 AM
IngePrefontaine
New Contributor

I have a c# project that makes an http "addFeatures" post request to a Feature Service that the GIS folks in my organization made available. Everything seems to be working and I'm able to deserialize the json response, but I'm finding that the json object it returns is not always the same structure - specifically, if an error was encountered the "AddResults" is missing.

The documentation here suggests that everything, whether success or error, will be wrapped in an "addResults" []. Add Features—ArcGIS REST API: Services Directory | ArcGIS for Developers 

But what I'm finding is that if it's successful I get this returned (as expected):

{
   "addResults": [
      {
         "objectId": 40822,
         "success": true
      }
   ]

}

And if an error occurred I get this returned (notice the "addResults" is missing):

{
   "error": {
      "code": 500,
      "message": "Unable to complete operation.",
      "details": [
         "Parser error: Some parameters could not be recognized."
      ]
   }
}

This makes it hard to deserialize into an object because there are two different structures. I had to create a model for each to work around this, is there a better way? Or is there something wrong with the setup of the Feature Service and it should always include the "AddResults" so that we can deserialize into one object?

Here's my code that's calling Feature Service in case that makes a difference. The "returnData" variable holds the returned json that I posted above:

// Add required parameters
var sendparams = new Dictionary<string, string>();
sendparams.Add("f", "json");
sendparams.Add("features", featuresTxt);
sendparams.Add("rollbackOnFailure", "true");

var req = new HttpRequestMessage(HttpMethod.Post, uri) { Content = new FormUrlEncodedContent(sendparams) };
HttpResponseMessage resp = await client.SendAsync(req);


var returnData = resp.Content.ReadAsStringAsync().Result;

Any help is appreciated, thanks!

0 Kudos
0 Replies