Is there a way to complete this cURL request in Javascript?
curl -X POST https://api.mongohq.com/databases/vehicles/collections/rockets/documents?_apikey=12345 \
-H "Content-Type: application/json" \
-d '{"document" : {"_id" : "bottle", "pilot_name" : "Elton John"}, "safe" : true }'
The below code is as close as I've been able to get, but it returns {"error":"Failed to create mongohq::api::document"}.
function postsBeaconMessage (postTo, beaconMessage , targetFrame) {
var beacon = document.createElement("form");
beacon.method="POST";
beacon.action = postTo;
//beacon.target = targetFrame;
var message = document.createElement("input") ;
message.setAttribute("type", "hidden") ;
message.setAttribute("name", "document") ;
message.setAttribute("value", beaconMessage);
beacon.appendChild(message) ;
beacon.submit();
}
I get a 500 error when I execute this, but the cURL works fine. I assume it's an issue with setting the content type. Is there a way to set the content type in the form or post object? It seems mongohq requires an explicit content type declaration.
I don't have access to change the same-origin policy on the server, and I'm pretty sure I won't be able to execute PHP.
Any thoughts would be helpful. I'm dead in the water here.