How to access the attributes of an http response in another http task?

I am trying to design a flow containing more than 2 rest APIs. I would like to use the response parameters of the 1st REST API in subsequent API calls.

Could you please help in providing information on how to achieve this using flowable HTTP task. Also, any examples for flowable http task would be really appreciated . I have already gone through the http task documentation, but as I am new to Flowable , I am not able to figure out the steps to extract http response.

P.S - I would prefer to define the process mainly with HTTP tasks alone.


The way I do this is: I always put a Script task before an Http task. In that Script task, I set up everything I will need in the REST API call done from Http task.

Example of a Groovy script that sets up my request body, headers and endpoint URL:

final String json = '{"idDokumenta":@docid@,azuriraj":false}';
final String dokumentid = execution.getVariable("dokumentid").toString();
String res = json.replace("@docid@", dokumentid);
execution.setVariable("requestBody", res);
execution.setVariable("requestUrl", "http://localhost:8080/api/test");
execution.setVariable("requestHeaders", "Accept: application/json");

Then, in the Http task configuration/properties, you do/fill this:

Little below that, you need to do fill stuff like this as well:

After the HTTP call has been made, your response JSON will be saved in the process variable under the name myResponse.

You can use that variable in the future Script tasks, and here’s an example where I do that to fetch two field values from a response body:

final def resp = execution.getVariable("myResponse");
final String status = resp.status.toString();
final String error = resp.error.toString();

Both status and error and respective fields in the said JSON response, like so:

    "status": "OK",
    "error": "NONE"

I hope this helps :slight_smile:

1 Like

Thank you, very much @fiki574 . You are a lifesaver. :slight_smile: The answer is very detailed and clear. I have one doubt though, how do I pass multiple request headers ? Should I separate them with comma or semi-colon?

Hey. You use simple new line character \n, like so:

execution.setVariable("requestHeaders", "Accept: application/json\nContent-Type: application/json");

I’m glad I helped :slight_smile:

Unfortunately I get error :
No such property: execution for class
how may I make the script task know the variable execution ?

Are you in a case? You should use caseInstance or planItemInstance then.

Yep caseInstance seems accepted but again the same problem of using these variables later in httpTask not accepted :confused: 9521
Can you help please ? blocked now for days because of this we can’t use httpTask in cmmn dynamically

See my response to your other post Cmmn Http Task Requestbody Construct Json Issue - #6 by poly

See my response on the other post: the flowable:string most likely should be flowable:expression, the engine executes what is in the model and that’s the instruction to inject it as a string. How are you using Flowable? Are you able to change the XML before deployment (which is a workaround)?