Flex addFeatures using REST API

3328
1
Jump to solution
08-12-2014 07:27 AM
TylerWaring
Occasional Contributor II

Greetings,

    I am attempting to add features from a Flex application using the REST API addFeature call. I pieced together a function from various sources But it doesn't seem to do much:

private function addGraphicToEasementLayer(graphic:Graphic):void
{
var easementJSON:Object = graphic.toJSON();
trace("the Easement is " + easementJSON);
var httpService:HTTPService = new HTTPService();
httpService.url = 'http://domain/ArcGIS/rest/services/SharedMaps/GreenwayEasementsTest/FeatureServer/1/addFeatures?f=js...
httpService.send();
}

This function runs and does not produce an error. However, it also does not add my easement feature.Has anyone tried adding JSON Features to a featureService using both the Flex and REST APIs? Any tips, tricks, points or general information will be greatly appreciated.

Thanks, Tyler 

0 Kudos
1 Solution

Accepted Solutions
TylerWaring
Occasional Contributor II

You have to POST the URLRequest and assign the variables using URLVariables. What I really needed to do is something like this:

private function addGraphicToEasementLayer(graphic:Graphic):void

  {

  var easementJSON:Object = graphic.toJSON();

  var easmentString:String = "["+JSONUtil.encode(easementJSON)+"]";

  trace("the Easement is " + easmentString);

  var request:URLRequest = new     URLRequest('http://yourdomain/ArcGIS/rest/services/SharedMaps/GreenwayEasementsTest/FeatureServer/0/addFeatures'...

  var urlVars:URLVariables = new URLVariables();

  urlVars.f = "json";

  urlVars.features = easmentString;

  urlVars.gdbVersion = "";

  urlVars.rollbackOnFailure = true;

  request.data = urlVars;

  request.method = URLRequestMethod.POST;

  var loader:URLLoader = new URLLoader();

  loader.load(request);

  }

Works like a charm!

Hope this helps someone else.

Thanks, Tyler

View solution in original post

0 Kudos
1 Reply
TylerWaring
Occasional Contributor II

You have to POST the URLRequest and assign the variables using URLVariables. What I really needed to do is something like this:

private function addGraphicToEasementLayer(graphic:Graphic):void

  {

  var easementJSON:Object = graphic.toJSON();

  var easmentString:String = "["+JSONUtil.encode(easementJSON)+"]";

  trace("the Easement is " + easmentString);

  var request:URLRequest = new     URLRequest('http://yourdomain/ArcGIS/rest/services/SharedMaps/GreenwayEasementsTest/FeatureServer/0/addFeatures'...

  var urlVars:URLVariables = new URLVariables();

  urlVars.f = "json";

  urlVars.features = easmentString;

  urlVars.gdbVersion = "";

  urlVars.rollbackOnFailure = true;

  request.data = urlVars;

  request.method = URLRequestMethod.POST;

  var loader:URLLoader = new URLLoader();

  loader.load(request);

  }

Works like a charm!

Hope this helps someone else.

Thanks, Tyler

0 Kudos