Using esriRequest to make POST changes to REST feature using updateDefinition?

07-14-2018 11:36 AM
New Contributor II

I've worked with ajax requests before, but I'm trying to make changes to a Feature Service using updateDefintion but I can't seem to get it to work.  For debugging purposes, I've modified this example: Request data from a remote server | ArcGIS API for JavaScript 4.8 

I'm able to plug in the Feature Service to properly get a response using GET, but  when trying to use a FormData to load JSON as the payload for updateDefinition, I don't get a response. I modified a small amount of data to effectively try to use something simple as:

var item = {
"minScale" : 10,
"maxScale" : 0

var formData = new FormData();

for ( var key in item ) {
   formData.append(key, item[key]);

// Make the request on a button click using the
// value of the 'input' text.
on(btnQuery, "click", function() {
 var url = input.value;
 esriRequest(url, {
 responseType: "json",
 method: "post",
 body: formData
}).then(function(response) {
console.log('response', response);
var responseJSON = JSON.stringify(response, null, 2);
resultsDiv.innerHTML = responseJSON;

Essentially, just taking the 'item' JSON and converting it to FormData and then using FormData as the  payload. Additonally, the URL that isbeing used is of the format:

Here, I am simply appending 'updateDefiniton' as the method to use for modifying the service, as documented here:

Update Definition (Feature Layer)—ArcGIS REST API: Services Directory | ArcGIS for Developers 

I don't get any errors, and there are obviously no changes being made.  Do I need to adjust any settings onthe Feature Service itself? Am I missing something?

0 Kudos
2 Replies
New Contributor

What are you trying to update exactly? It sounds like your trying to update data in the feature service and not necessarily the definition itself. Are you trying to update features or the definition? Can you explain from a business perspective on what you are trying to accomplish?

0 Kudos
New Contributor II

At the moment, you can see that I am just trying to update the definition. I tried something  simple like minScale. Eventually I Would like to create a feature service using JSON and POST

0 Kudos