How to pass values in Request Body for a POST call in flowable Modeller

Hi,
Could you please give me a sample on how to pass values in Request Body for a POST call in Flowable Modeller

I need to pass the below value in POST Call.

I created the below in script task.

execution.setVariable(“namevar”,“testname”);

var param =
{
“value”: 1,
“Name”: namevar,
};

execution.setVariable(“param”,param);

I am passing ${param} in request Body. but it fails in script itself saying "Coudln’t find a variable type that is able to serialize[object Object].

Thanks,
Esther

1 Like

Hi Esther,

The problem is that you are trying to serialize variable of Object type which does not implement serializable interface. In case of serializable is implemented flowable uses java serialization to persist the instance. I would not recommend it.
Use JSON instead.
Regards
Martin

Hi Martin,

Thank you for the reply. Could you pls provide a sample for the above scenario. It would be a great help.

Thanks.

Sample is not so easy to prepare, because I do not know your use case. If you prepare your usecase in the jUNit test I can try to propose a fix.

Regards
Martin

Hey.

This is how I do it: How to access the attributes of an http response in another http task? - #2 by fiki574

The generic pattern I use, when doing a POST request body in a JSON approach, is to break out the bits of data you need into each parameter. Using your object, param, that has a field name and a field value, it could look like this when setting the request Body field in the modeler:

paramA=${param.Name}&paramB=${param.value}

The goal, basically, is to make sure that all your data being passed over the wire is either a string or a java primitive (int, boolean, etc). Strings and primitives don’t get serialized so you won’t get errors. Also, it’s easier to debug because you can dump out your request body variables to a log file if you need to.

As for the number of variables, if you find yourself needing a dynamic number of variables I would rethink your approach. I’ve done a fair number of HTTP POST requests using the modeler. I’ve never had to use a variable Request Body size (where I have between 0 and n arguments).