How can I use process variables in a HTTP Task?

I want to perform a HTTP Task to trigger an outside service, but I need to include -something- in the outgoing POST for the service to use for the POST back, how can I access them?

{
‘email’: ${email},
‘reference’: ${mitozreference},
‘pickupdate’: ${pickupdate},
‘pickuptime’: ${pickuptime},
‘info’: ${shipmentinfo}
}

There are two ways I read this.

The first is that you want to send those values as part of your FORM to post to your endpoint. Here’s how I handle that approach:

  1. In the modeler, set the verb to POST (kind of self-explanatory, but I’m listing it all out)
  2. Set the “Request Headers” property in the modeler. I use “Content-type: application/x-www-form-urlencoded” in all my POST headers when I need to send data. I also have an “Authorization: Bearer ${token}” header because all my POST endpoints require a security token (which is supplied into the workflow during task completion).
  3. Set the Request URL value. This needs to be the fully qualified URL to hit (so http://www.yourdomain.com/yourEndpoint
  4. Set the request body parameters. The format for this is "email=${email}&reference=${mitozreference} … " and that is how you attach your process variables to the request body. (The … is because I’m lazy and didn’t want to type it out, but keep adding parameters using the & until you are done putting stuff in there).

The framework I’m using understands how to parse out the request body for me, so my endpoint function sort of looks like this:

myEndpoint (string email, string reference, … ) { … }

The other way I read that question is that your endpoint does stuff to process variables, and you want the POST response to return useful details to you. Well the easiest way to handle that is also in the modeler, and I use these steps:

  1. Make sure that your endpoint function returns a JSON payload
  2. Put a value into the “Result variable prefix” section of the HTTP service in the modeler. Whatever your put here you get the word “ResponseBody” attached to it by Flowable. More on that later.
  3. Set “Save response as JSON” to true

What happens now is that your HTTP service will respond with a JSON value. That value is stored into the process level variables automagically as “myPrefixResponseBody” (assuming you set “myPrefix” back in step 2). To access that value during the course of your workflow, simply go

${ myPrefixResponseBody.info }

where the .info is maybe something you had updated/set during the course of your POST function.

Hopefully that helps.