How to derive a REST request body from a process state?

The docs only explain how to create a static request body. It gives this example:

= {
     "temp": 25,
     "pressure": 1013,
     "humidity": 44,
     "temp_min": 16,
     "temp_max": 30
}

I’ve tried using template expressions and direct references, but with no luck.

Given the variable user_message, I’ve tried the template expression "{user_message}" (notice I’m including the quotes):

{
  "state": "{{user_message}}",
  "model": "jev-latest",
  "questions": {
     "is_urgent": {
      "type": "noul",
      "instructions": "The message conveys urgency or time-sensitivity"
    }
  }
}

Which doesn’t crash, but I think the request includes the literal template expression {{user_message}} instead of the expansion of the variable user_message, because what I can infer from the response (this is another issue BTW: I don’t know how to log the actual request).

I’ve tried direct reference to the variable:

{
  "state": user_message,
  "model": "jev-latest",
  "questions": {
     "is_urgent": {
      "type": "noul",
      "instructions": "The message conveys urgency or time-sensitivity"
    }
  }
}

But Camunda Operation reports an incident “Job: No retries left.” The same issue happens if I try {{ user_message }} instead.

So… how can I derive the request body from the process state?

In Camunda 8, the important point is that the REST Connector request body is FEEL, not a normal JSON/Handlebars template.

So {{user_message}} is not the right syntax.

If user_message is a process variable containing a string, you can build the body as a FEEL context:

= {
  "state": user_message,
  "model": "jev-latest",
  "questions": {
    "is_urgent": {
      "type": "noul",
      "instructions": "The message conveys urgency or time-sensitivity"
    }
  }
}

Why the first attempt doesn’t work

This:

{
  "state": "{{user_message}}"
}

is just a literal JSON string as far as the connector is concerned. Camunda doesn’t automatically interpret {{...}} as a process-variable expression there.

And this:

{
  "state": user_message
}

is invalid JSON because JSON requires a string value to be quoted. But if the entire field is configured as a FEEL expression, then:

= {
  "state": user_message
}

is valid.

If you want to combine text with a variable

For example:

= {
  "state": "User message: " + user_message,
  "model": "jev-latest"
}

Or, if you need JSON serialization as a string rather than an object, you can use the appropriate JSON/string conversion supported by your connector configuration.

Agree with the FEEL context approach. One small thing that tripped me up: don’t forget the leading = in the body field, otherwise the whole thing gets sent as a plain string. If user_message can be null, you can wrap it like if user_message = null then “” else user_message so the request doesn’t break.