Camunda 8 loop through response body

I would like to loop through the response body containing a list of objects, then returning a specific field of the object matched:

This works fine, however when I replace the value of comparison with a variable, it will not work. The variable seems to not expand at all:

any insight appreciated

Hi @jpbell - hmm, that expression should work. Here’s a test in the FEEL Playground demonstrating it …

Are you certain bu has a value that matches a name in the response objects? When you run your process, are there any incidents or errors in Operate?

After some more testing, it appears to work when mapped in “outputs” to a process variable name, but not when it is mapped in a response mapping.

in operate, mapped in the Outputs of an end event:

it’s interesting to note that domain_label (mapped in the result expression of the REST connector) does not even appear in the list of variables.

@jpbell - that is curious … one follow up question, so I can better determine how to best report this back to the product team as a bug:

In your original configuration from the first post (without the additional output mapping), if you leave the “Result variable” blank and only provide the “Result expression”, do you get a different result?

Also some environment information:

  • are you using SaaS or a Self-Managed instance?
  • if SaaS, what version is your cluster running? If Self-Managed, what version of Zeebe and the Connector Runtime/bundle are you using?

No dice, doesn’t work with result variable blank either.

I am self-managed, version 8.4.4 for Zeebe and connector runtime

@jpbell - I just realized the answer, and feel a bit silly I didn’t realize it earlier! This isn’t a bug, but the documentation can use some work here.

The “Result expression” is invoked inside the Runtime, which only has access to the data from the request/response itself, not to any process variables. (You can see that here in the code.) This is why it works when you provide a hard-coded string value for the filter comparison, but not when you a process variable. However, the output mapping is handled by the process engine itself, after the Connector has returned.

For your example, you could trim the response using a “Result expression” like ={ items: response.body } then in the output mapping you can output a variable named domain_label with an expression value of =items[ = string(bu) ].label[1]. You can omit the “Response variable” value entirely, unless you want to the entire response from the API available as a global process variable.

I think the correct way to think of the “Result expression” field is “I don’t need the whole response back, just these bits of data.”

I’ll raise a ticket with our documentation team and find a way to make this more clear in the documentation.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.