Rest Service Call From Javascript Script

I want to call a REST service from a javascript external resource in camunda bpmn but I can’t find a way to make the http request from within the script. I don’t want to use the http connector and service task.

Can this be done in camunda?

If you script is placed in the bmp modell, it will be executed on the server so you can try:

var resourceURL = new java.net.URL("https://httpbin.org/get");

var urlConnection = resourceURL.openConnection();
var inputStream = new java.io.InputStreamReader(urlConnection
        .getInputStream());
var bufferedReader = new java.io.BufferedReader(inputStream);
var inputLine =""
var text="";
while ((inputLine = bufferedReader.readLine()) != null) {
				text+=inputLine
			}
bufferedReader.close();

//.... do somthing with the text
4 Likes

Hi @abdallah,

I am not sure I get your question, where REST service should be called from? Could you be a bit more specific about it?

Cheers,
Askar

I already have my api. I want to make an api call from the script(javascript) in a task script.
How can i choose the request url and method and set authorization.

well, in that case I think @Robert_Ottohall has a valid suggestion to solve your problem.

Hope that helps,
Askar

Thanks!This worked well for me.

Hi @Robert_Ottohall,

How can I add method like POST, GET… etc…? And also, how can I add input parameters to it.?

Thanks,
Nihir Shah