Select to view content in your preferred language

How to post to ArcGIS REST API for 'apply edits' functionality dotnet core

2606
1
05-20-2021 06:34 AM
DeveloperCSharp
New Contributor

Hi,
I am using the help of ARCGIS API in Angular to draw and post the data. But the data that is obtained in my angular app is passed via web api which is in asp.net core. I have done this to make sure that all my gis api calls happen via the server. 

I had seen that the following is the syntax to post the data for apply edits (Feature Service/ Layer).

adds=[<feature1>, <feature2>]

But I am confused on how to post the data via my web api using http client. Please provide a sample request through which I can post my data to applyedits endpoint. I tried converting my model to Json format but I couldn't succeed. 

 

0 Kudos
1 Reply
TommyBramble
New Contributor III

This worked for me:

            string url = "{{...URL...}}/FeatureServer/0/applyEdits";

            string adds = "[{\"geometry\":{\"x\":-118,\"y\":33},\"attributes\":{\"Name\":\"name\",\"Type\":\"type\",\"Column3\":\"value3\"}}]";

            var inputParms = new Dictionary<string, string>();
            inputParms.Add("adds", adds);
            //inputParms.Add("updates", "");
            //inputParms.Add("deletes", "");
            //inputParms.Add("attachments", "");
            inputParms.Add("f", "json");
            //inputParms.Add("token", "");

            var input = new FormUrlEncodedContent(inputParms);

            HttpClient client = new HttpClient();

            var response = client.PostAsync(url, input).Result;
            var responseString = response.EnsureSuccessStatusCode().Content.ReadAsStringAsync().Result;

 

If you have a secure service, then the token parameter will need to be populated with a valid security token.

responseString contains the serialized JSON string that you can work with. In my testing the result was 

{"addResults":[{"objectId":10,"uniqueId":10,"globalId":null,"success":true}],"updateResults":[],"deleteResults":[]}

 

Other resources:

https://developers.arcgis.com/rest/services-reference/enterprise/apply-edits-feature-service-layer-....

https://stackoverflow.com/questions/4015324/how-to-make-an-http-post-web-request

https://developers.arcgis.com/rest/users-groups-and-items/generate-token.htm

 

0 Kudos