How to call external API in Camunda Form

Hi Team,

I have made inbuild camunda form adding some fields like: Name and Location(selection field).
We need to bind location data through API call. But I have no idea about how to call external api in Camunda form.
image

Please share any demo file.

Regards,
Santosh

Hi Santos,
viewing, filling, and submitting a form is done by a user, hence a user task.
Retrieving data from an API is a service call; thus, I’d recommend adding a service task before the user task. The service task calls the API and stores relevant information in variables.
The content of these variables can be shown inside the form.

Does this fit your use case?

– Stephan

Hi Stephan,

Thanks for quick reply.
If you have any demo bpmn file and Camunda form example. Its really helpful for us. We have tried that way too but not able to load data in the location select field.

Regards,
Santosh

The following example (tested with Camunda Run 7.17) has two tasks:
a script task that sets the value of the variable location to "Germany"followed by a user task that uses the provided form. The location field is already pre-filled with the value of the variable. For this to work, the key of the field and the name of the variable must match.

To adapt it to your use case, consider changing the script task into a full-fledged service task that calls the API, extracts the location, and sets the variable.

SelectLocationProcess.bpmn (3.4 KB)
location.form (1.1 KB)

1 Like

Hi Stephan,

What I did.
I have created a new bpmn file and placed service task and user task.
in service task: using http-connector to call dummy endpoint call to get all emp lists.
User task : create new camunda form to get only employee name.
But can’t able to bind selectbox.
I am sharing both bpmn and camunda form.

Regards,
Santosh
Emp.bpmn (3.5 KB)
EmployeeName.form (382 Bytes)

Hi Santaosh,

so, EmpLists holds a list of employee objects, is that right?
In that case, you can use an input mapping with a JUEL expression to transform your list into a list of Strings (employee names).

Hi,

Thanks for update,
I never use JUEL expression. could you plz try on my bpmn file.
Thank you in advance.

Hi Santosh,

Let me briefly summarize:
You have a variable EmpLists holding a list of employee objects, e.g.,

[{
  "name":"Santosh",
  "email":"santosh@example.com"
},
{
  "name":"Stephan",
  "email":"stephan@example.com"
}]

Now, you want to be able to use a select-input to choose either Santosh or Stephan?

This is currently not possible: Within Camunda forms, options of a select field must be hard-coded.
However, if you want to pre-select a value based on a variable. You can use a JUEL expression.

Let’s assume you have only one employee object:

empObj = {
  "name":"Santosh",
  "email":"santosh@example.com"
}

And your form as a select field, in which you can choose an employee (name), and the selected name will be stored in the variable empName. In this case, you can use an input mapping to preselect the current employee’s name:

image

I hope this helps.