Has anyone successfully called "addToDefinition" for a feature layer?

Discussion created by bberdel on Nov 26, 2013
Latest reply on Apr 23, 2014 by bberdel

I am trying to call the REST service "addToDefinition" from within my C# code for a feature layer (that requires a token) that I havepublished to my ArcGIS online account.

I am using the RestSharp library to instantiate/manage the REST call.

This is the API reference provided by ESRI:

The problem is that I keep getting "error code: 400 Object reference not set to an instance of an object".

I have verified that I am pointing at the correct URL for updating the feature layer:

It looks as if the "f" and "token" parameters cannot be part of the request body, or the service will not find them. So I have added them as parameters to the URL of the REST service, and everything is getting through at that level.

The problem is that when I add the "fields" parameter to the body of the request, I get the error 400 code. I have tried adding it as a post parameter, a serialized object, a serialized string, but I keep getting the same error. It's almost as if the parameter isn't being accepted by the service.

When I copy and paste the same "fields" parameter my C# is trying to pass to the REST service directly into the REST parameter for on the link, it works just fine.

Has anyone come across this before/been able to successfully call this REST service from C# code?

Any help would be greatly appreciated.