How exactly should I use PUT/POST in Http task when I am limited to only strings for Request body

Hey everyone,

In request body I can only type out my JSON body, but can’t use variables (ones I got using script task), i.e. ${myVar}, since those are strings with quotation and unsuitable for REST calls.

Any advice on using REST API?

I’m using HTTP tasks for API calls with variables from script tasks without problems. Example:

<serviceTask id="http_example_task" name="HTTP example task" flowable:type="http">
  <extensionElements>
    <flowable:field name="requestMethod">
      <flowable:string><![CDATA[PUT]]></flowable:string>
    </flowable:field>
    <flowable:field name="requestUrl">
      <flowable:expression><![CDATA[${propertyService.getValue('my.domain.url')}/app/api/v1/endpoint]]></flowable:expression>
    </flowable:field>
    <flowable:field name="requestHeaders">
      <flowable:string><![CDATA[Content-type: application/json]]></flowable:string>
    </flowable:field>
    <flowable:field name="requestBody">
      <flowable:expression><![CDATA[${jsonVariable}]]></flowable:expression>
    </flowable:field>
    <flowable:field name="failStatusCodes">
      <flowable:string><![CDATA[400,401,403,404,415,500]]></flowable:string>
    </flowable:field>
  </extensionElements>
</serviceTask>

Please mind the flowable:expression when you need to evaluate variable.

1 Like

Thanks.
It seems I can’t set the type from inside the modeler. Any quick workaround?

You don’t need to, when selecting the Http task, the type will be set automatically for you.

That’s true, but I need to set the type of a service task if I want to use those fields.

Which modeler are you using? With the flowable-modeler application has a specific HTTP Task that you can drag and drop and you would be able to add all the information that @jan linked in the modeler

Hey,

I need the request body to be an expression, not a string. I think it’s string since my test cases failed and I think it’s due to quotation.

Exactly and if you go in the editor and in request body you write: ${bodyExpression} then you will have

<flowable:field name="requestBody">
    <flowable:expression><![CDATA[${bodyExpression}]]></flowable:expression>
</flowable:field>

in your BPMN xml. Can you perhaps share a reproducal with your problem. Perhaps the test case and the BPMN XML. As this should work

1 Like

You are correct. I will reply again If I don’t get it working. Thanks

It works now. First time I downloaded BPMN XML I got the !CDATA[GET] instead of !CDATA[PUT]. But the next day it was PUT, and it everything just worked. I haven’t changed anything in comparison to what I had when I posted the problem.

Thanks for helping out.