AnsweredAssumed Answered

REST API for adding a record

Question asked by ndilekli on May 22, 2017
Latest reply on May 23, 2017 by ndilekli

I would like to add records to a table using REST API. I followed Robert Scheitlin, GISP's example to retrieve a table here, and modified the URL with the following one:

"http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1/addFeatures?features=[{'attributes' : {'agree_with_incident' : '2', 'notes' : 'my notes..'}}]&f=json";

based on Domenico Ciavarella's answer in this post. However, I am getting this error in the console when I try to execute the request: "dojo.io.script error Error: Unable to complete operation." 

 

I am very new to the REST API, and I don't see many examples. Here is my entire code

 

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>Add a Record</title>
  <style>
    td {
      padding: 4px;
    }

    #loading {
      visibility: hidden;
    }
  </style>

  <script src="http://js.arcgis.com/4.2/"></script>

  <script>
    require([
      "esri/request",
      "esri/config",
      "dojo/json",
      "dojo/dom",
      "dojo/on",
      "dojo/domReady!"
    ], function(esriRequest, esriConfig, JSON, dom, on) {

      esriConfig.request.proxyUrl = "http://gislap183/js/proxy/proxy.ashx";

      function doRequest(){
        var url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1/addFeatures?features=[{'attributes' : {'agree_with_incident' : '2', 'notes' : 'my notes..'}}]&f=json";
        esriRequest(url, {
          responseType: "json",
          callbackParamName: "callback"
        }).then(function(response){
          showResults(response);
        });
      }

      var resultsTable = dom.byId("tbl");

      // Executes when the promise from find.execute() resolves
      function showResults(response) {
        var results = response.data;
        // Clear the cells and rows of the table to make room for new results
        resultsTable.innerHTML =  JSON.stringify(results);
      }

      // Executes each time the promise from find.execute() is rejected.
      function rejectedPromise(err) {
        console.error("Promise didn't resolve: ", err.message);
      }

      // Run doRequest() when button is clicked
      on(dom.byId("execBtn"), "click", doRequest);
    });
  </script>

</head>
<body>
  <input type="button" value="Execute" id="execBtn" />
  <br>
  <br>
  <table id="tbl"></table>
</body>
</html>

 

How can I fix this? Thanks.

Outcomes