How can I call an API from the UI Designer?
Hi everyone,
I want to call an API (not Bonita API) from a JavaScript variable from the UI Designer. I have the following code:
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?
Thanks,
Clara
1 answer
Hi Clara,
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