I wasn't quite sure whether to ask this here or in the GIS Stack Exchance. Possibly both. But I feel I'm doing something fundamentally wrong here - the update doesn't seem to be taking effect (when I look in the console afterwards it's still false).
I'm writing a process in C# to update a Feature Layer's definition and make it able to sync. The bits of code I've written so far for other processes (uploading new files and downloading queries) work fine, I'm just having some issues with this one and think I need a few pointers. Official resources can be found on the below links:
Update Definition (Feature Service)
Update Definition (Feature Layer)
The code I have is:
static async Task<string> ReSync(string myToken, string ServiceUrl)
{
try
{
var client = new System.Net.Http.HttpClient();
HttpContent content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("f", "json"),
new KeyValuePair<string, string>("token", myToken),
new KeyValuePair<string, string>("async", "true"),
new KeyValuePair<string, string>("syncEnabled", "true"),
new KeyValuePair<string, string>("capabilities", "Query,Editing,Create,Update,Delete,Sync")
});
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var response = await client.PostAsync(ServiceUrl, content);
var responseString = await response.Content.ReadAsStringAsync();
return responseString + " <> " + ServiceUrl + " <> " + content;
}
catch (Exception exception)
{
return exception.ToString();
}
}
With my ServiceUrl being along the lines of:
The responseString returned (the response, ServiceUrl, and content, in that order) is:
{"statusURL":"https://servicesX.arcgis.com//MyCompanyID/ArcGIS/rest/admin/services/MyLayerName/FeatureServer/updateDefinition/a-few-numbers-go-here"} <> https://servicesX.arcgis.com/MyCompanyID/arcgis/rest/admin/services/MyLayerName/FeatureServer/updateDefinition <> System.Net.Http.FormUrlEncodedContent
If I do it manually (from the ArcGIS Online console) and record the response in Chrome's DevTools, we get (important bits):
General
Request URL: https://servicesX.arcgis.com/MyCompanyID/arcgis/rest/admin/services/MyLayerName/FeatureServer/updateDefinition
Request Method: POST
Form Data
updateDefinition: {"hasStaticData":false,"capabilities":"Query,Editing,Create,Update,Delete,Sync","editorTrackingInfo":{"enableEditorTracking":false,"enableOwnershipAccessControl":false,"allowOthersToUpdate":true,"allowOthersToDelete":true,"allowOthersToQuery":true,"allowAnonymousToUpdate":true,"allowAnonymousToDelete":true}}
async: true
f: json
token: LotsAndLotsOfCharactersAndStuff