I’m using Adobe AIR and integrating with the force.com platform via the REST API, and so far it’s been relatively smooth sailing, but I’m coming unstuck on using the DELETE method.
The documentation is simple enough:
Deleting an Account Record
Use the DELETE method to delete a record.
In this example, an Account record is deleted.Example usage for deleting fields in an Account object
curl https://instancename.salesforce.com/services/data/v20.0/sobjects/Account/001D000000INjVe
-H “Authorization: Bearer token” -H “X-PrettyPrint:1” -X DELETEExample request body for deleting an Account record
none required
Example response body for deleting an Account record
none returned
My code is below, note that the second parameter of HTTPConnection.send() is the method to call.
var headers:Object = new Object();
headers["Authorization"] = "Bearer "+ConnectionAccessToken;
var url:String = ConnectionInstanceURL + "/services/data/v"+_apiVersionNumber+"/sobjects/"+type+"/"+id;
var response:RESTResponse = new RESTResponse(callback);
var httpCallback:IResponder = new mx.rpc.Responder(response.resultHandler,response.faultHandler);
HTTPConnection.send(headers,"DELETE",url,httpCallback);
Similar code works perfectly for other operations, and the weird thing is that this doesn’t fail per se, rather it receives a success response, but gets the record in question back with all of it’s fields. It would appear that I’m seeing the results of [select * from Object where Id = <id>, and just to clarify the record is not deleted. The object doesn’t have any master detail relationships, so I’m not sure what else might be stopping this delete from happening — has anyone run into this before or have suggestions on how to resolve it?
With the setup I am using (where HTTPConnection is a custom class using HTTPService internally), the Adobe documentation states that the only HTTP methods available for me to use are just GET and POST:
This is why the delete was failing as it must have been sending as a GET instead as per jkraybill‘s comment above. After experimenting I have found that POST can be used, with the actual method to call included as a parameter to the URL: