I want to do an HTTP POST
from inside an iMacro to an API endpoint. Effectively, something like the following:
curl -d "data=foo" http://example.com/API
In iMacros, it might look something like this:
my-imacro.iimVERSION BUILD=10.4.28.1074
TAB T=1
URL GOTO=javascript:post('http://example.com/API', {data: 'foo'});
function post(path, params, method) {
// Reference: http://stackoverflow.com/a/133997/1640892
method = method || "post";
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for (var key in params) {
if (params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
But the above seems like a long and difficult way to do this. If it even works.
Is there a shorter, more direct or efficient solution?