How can I call an API from the UI Designer?
var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", URL, true); xmlhttp.setRequestHeader("Authorization", ENCODED_PW); xmlhttp.setRequestHeader("Accept", "application/json"); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(); return xmlhttp.status;
It's always returning a 0 error. It seems to be related CORS headers because I'm calling a cross-domain resource. When I call the API from the Studio I get the expected resource.
Any idea if I need to configure something in Bonita or if I should modify the code?
Yes, you are bumping up against cross origin resource sharing in your browser. There are a couple of options:
1) Call the code using a script connector. Since that's done server side there won't be any CORS issues
2) Disable CORS in your browser. Not highly recommended but it is possible in Chrome