Attach JSON to a task and retrieve it through the REST API

Hi,

we’re looking for a way to attach JSON data to user tasks and retrieve it through the REST API.

We’re using camunda BPM in a non-java environment (developers don’t commonly use Java, engine is just used as one docker container amongst other services, mainly written in node.js, in a microservices environment).

We use camunda BPM mainly to persist state in long-running processes, to make complex decisions within those processes, and to separate the process definition from the source code of the application and make it configurable.

We’re aware of the task form feature, where you reference a form by form key, but as we’re not using much Java, the fact that you need to build, package and deploy a java process application as opposed to just deploying a process definition via HTTP is a downside.

We found the form variables to be a workaround (just add a form variable of type String with a default value that is JSON), but are wondering whether there is a cleaner way to achieve this.

Looking forward to your replies!

Thank you and have a good day!
Nils

Hi Nils,

Nice to see you around. Do you look for a solution where the JSON is part of the BPMN file or can it be a separate resource?

Cheers,
Thorben

Hey Thorben!

Ideally the JSON would be part of the BPMN. However, if it is possible to create an archive that does not require a “full-blown Java application”, it would also be fine for us to deploy JSON files along with the process definition.

Any ideas how to achieve that?

Thanks and looking forward to your reply!
Nils

Just to elaborate on that, the docs mention process archives… I wasn’t sure whether those always require a Java class that is annotated as a process application. Maybe you can shed some light on that.

Thanks!

Hi Nils,

A deployment can contain multiple resources of any type. In the Java API, you would add resources via the DeploymentBuilder methods. In the REST API, you can do that by adding more parts to the POST /deployment/create request. That way, you can also add JSON files to the deployment. Then you can query for the deployment’s resources and retrieve the resource’s content as you need it. You could have a naming convention for the JSON files, e.g. <process-id>.<activity-id>.json, to link JSON to activities.

To clarify process applications, process archives and the need for Java: The above-mentioned deployment methods are imperative ways to make a deployment via REST or Java. A process application is an abstraction on top of that, which allows to declaratively make a process deployment along with the deployment of a Java application in an application server. Essentially, Camunda’s application server integration detects a process application being deployed and then takes care of making a process deployment (by using the DeploymentBuilder Java API). In order to do that, it reads the processes.xml deployment descriptor, in which users can declare process archives, which tells Camunda which resources to select for a deployment. Every such archive will result in a separate process deployment.

When you are not developing applications in a Java environment, then you don’t have to worry about process applications and archives anyway.

Lastly, a clean option of keeping the JSON in the BPMN XML would be adding a custom BPMN extension element. You could then parse the BPMN whenever you need to access the JSON and would have to extend the modeler to expose the element, so this is probably more work.

Cheers,
Thorben

1 Like