FeatureServer addToDefinition successful submission?

3246
3
10-09-2013 07:36 AM
TomStimmell
New Contributor
Has anybody successfully posted to the admin addToDefinition service for feature servers? The sample JSON does not work and there is nowhere else in the API documentation, that I can find, that explains the syntax.

If anybody has been able to get this working, can you post some sample JSON?

http://resources.arcgis.com/en/help/arcgis-rest-api/#/Add_To_Definition_Feature_Service/02r300000230...
0 Kudos
3 Replies
CharlieFrye
Esri Contributor
I was able to make this work with a little help from our development team. Here is the example URL:
http://services.myserver.com/ERmEceOGq5cHrItq/ArcGIS/admin/services/example1.FeatureServer/addToDefinition

The blue portion is determined based on your organization. The best way to obtain what you'll need to include is to use either your browser's debug tools or something like Fiddler to capture the results of the Create Service button that is in your account's My Contents tab in the upper right. That will produce the local equivalent of the URL you'll need.

You should also have created a feature service in ArcMap and shared it in order to provide yourself a "template" to use (rather than inventing the JSON object containing the parameters). Make sure the layer has the appropriate schema and then assign the symbols in the fashion you'd like them. Use that service when using the Create Service button, for the "an existing feature service" option.

One other trick that is useful to know is once you've usedCreate service to get started, you can get to the REST services folder by first clicking on the REST URL in the new services's content item page and then clicking on the Services link in the upper left. Then change that URL to look like by changing "rest" to "admin":

http://services.myserver.com/ERmEceOGq5cHrItq/ArcGIS/admin/services

By first going through the Services Folder, you will set your browser up to manage your credentials (provided your ArcGIS Online credentials own the service) in order to get to the admin page for your service. If you do not own the service, you will not be able to access that page.
0 Kudos
AnttiKajanus1
Occasional Contributor III
Just curious,

It seems that we can change some of the service properties but if we for example try to add new field or change an alias (they are included in the json format in html pages) it wont go thru. Well, that's not surprise since it is related on how the data is stored but since it is included in the JSON at least I expect that I can work with those parts too.

In the documentation there is no good description what you change and what not.
0 Kudos
BrianBerdel
New Contributor III
I just figured this out a few minutes ago (after a couple weeks of trying).

I was trying to make this request from a C# backend using RestSharp libraries.

Here's what I did:

I made a class to represent the Esri Field object:

    [Serializable]
    public class ESRIFeatureLayerFieldDefinition
    {
        public string name { get; set; }
        public string type { get; set; }
        public string alias { get; set; }
        public string sqlType { get; set; }
        public int length { get; set; }
        public bool nullable { get; set; }
        public bool editable { get; set; }
        public string domain { get; set; }
        public string defaultValue { get; set; }
    }

from there I created a test field and added it to a list:

            ESRIFeatureLayerFieldDefinition addField = new ESRIFeatureLayerFieldDefinition();

            addField.name = "TestField14";
            addField.type = "esriFieldTypeString";
            addField.alias = "TestField14";
            addField.sqlType = "sqlTypeOther";
            addField.length = 150;
            addField.nullable = true;
            addField.editable = true;
            addField.domain = null;
            addField.defaultValue = null;
           
           
            List<ESRIFeatureLayerFieldDefinition> fieldList = new List<ESRIFeatureLayerFieldDefinition>();
            fieldList.Add(addField);

Next, I put that list into a dictionary of type string, object, and gave it a key of "fields":

Dictionary<string, object> fieldArray = new Dictionary<string, object>();
            fieldArray["fields"] = fieldList;

I created my RestRequest, specifying it as a "POST" method along with the URL to my service:
           
            RestRequest request = new RestRequest(url, Method.POST);
            request.Method = Method.POST;

Then I added a parameter for the fields.  The only thing is, the service is looking for a parameter called "addToDefinition" that CONTAINS the fields object.  (I found this out after using fiddler to analyze the request when I submitted a request through esri's web admin interface).

So, I have only one parameter in my request and it looks like this:

            request.AddParameter("addToDefinition", serializer.Serialize(fieldArray), ParameterType.GetOrPost);

The "addToDefinition" is the name of the parameter that the REST service is looking for.  I used a serializer to serialize the fieldArray dictionary object to get the fields JSON object as a string.  Parameter type was GetOrPost, and since it's only one it will be passed as the body of the request.

Any additional querystrings or parameters "f=pjson", "token=" were all appended to the resource URL for my request object.

Once that request completes, you should see the new field in your service definition.
0 Kudos