The new camunda BPMN model API

  • Blog
  • >
  • The new camunda BPMN model API
As already mentioned in our last alpha release blog post we are currently working on a BPMN model API to parse, create, edit and write BPMN 2.0 XML files. Last Friday we opened our GitHub repository and have since then created a userguide and some quickstarts.


The BPMN model API offers you a simple and straightforward way to interact with an BPMN 2.0 model. It enables you to gather information from an existing model, edit and extend them. Of course you can also create completely new ones.

Technically the model API is based on a DOM layer which is accessed and manipulated by a general XML API developed by us. On top of this, the BPMN model API encapsulates the interaction with the XML API. The BPMN model API as well as the XML API does not hold any state, which means only the DOM layer has the current model state. This enables us to read information which we currently are not aware of without the risk of losing such information. It also allows non-intrusive editing of BPMN Models, conserving custom formatting and source code comments.

In addition, if your BPMN 2.0 model contains custom elements or attributes they are always accessible even if they are not exposed through the high-level BPMN model Api. Although our BPMN model API cannot be aware of these custom extensions you can obtain and modify them easily with the generic XML API. Another benefit of this concept is that we can already show you the current state despite the fact that the current BPMN model API not yet implements all BPMN 2.0 elements. But the already supported elements are enough to create rather complex processes.

Just check it out!

Show me some code please

Okey after all this promises I want to show you some code examples so you can get a first impression what already is possible with the BPMN model API.

Lets start with a simple example.
simple example process
The following code creates this process with the plain BPMN model API and saves it to a new file.

public void testCreateProcess() {
  modelInstance = Bpmn.createEmptyModel();
  Definitions definitions = modelInstance.newInstance(Definitions.class);

  Process process = modelInstance.newInstance(Process.class);

  StartEvent startEvent = modelInstance.newInstance(StartEvent.class);

  UserTask userTask = modelInstance.newInstance(UserTask.class);
  userTask.setName("User Task");

  SequenceFlow sequenceFlow = modelInstance.newInstance(SequenceFlow.class);
  connect(sequenceFlow, startEvent, userTask);

  EndEvent endEvent = modelInstance.newInstance(EndEvent.class);

  sequenceFlow = modelInstance.newInstance(SequenceFlow.class);
  connect(sequenceFlow, userTask, endEvent);

  Bpmn.writeModelToFile(new File("target/new-process.bpmn"), modelInstance);

connect(SequenceFlow flow, FlowNode from, FlowNode to) {
This code generates the following BPMN 2.0 XML file.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<definitions targetNamespace="" xmlns="">
    <startEvent id="start">
    <userTask id="task" name="User Task">
    <sequenceFlow id="flow1" sourceRef="start" targetRef="task"/>
    <endEvent id="end">
    <sequenceFlow id="flow2" sourceRef="task" targetRef="end"/>

Fluent model builder API

Okey I know you say this looks very verbose and becomes easily hundred lines of code to create a complex task like this one.
complex process model
Although the BPMN model API gives you the possibility to modify the process definition in every aspect there should be an easier way to create process models like the above. And as you might expect here comes another great feature of the BPMN model API: our fluent model builder API. A simple way to create basic BPMN processes with the following BPMN elements:
  • process
  • start event
  • exclusive gateway
  • parallel gateway
  • script task
  • service task
  • user task
  • end event

So lets create this process fully deployable on our camunda BPM platform in less then 50 lines of code. Please have a look at the complete code in our quickstart.

BpmnModelInstance modelInstance = Bpmn.createProcess()
    .name("BPMN API Invoice Process")
    .name("Invoice received")
    .name("Assign Approver")
    .name("Approve Invoice")
      .name("Invoice approved?")
    .condition("yes", "${approved}")
      .name("Prepare Bank Transfer")
      .name("Archive Invoice")
      .name("Invoice processed")
    .condition("no", "${!approved}")
      .name("Review Invoice")
      .formKey("embedded:app:forms/review-invoice.html" )
        .name("Review successful?")
      .condition("no", "${!clarified}")
        .name("Invoice not processed")
      .condition("yes", "${clarified}")
To learn how to use the fluent builder API  have a look at our userguide. There you can find examples how to extend an existing process. For example to add a new execution path to a gateway or add new elements between two existing elements.
Well, what more can I say then to check it out and and give us feedback!

Camunda Developer Community

Join Camunda’s global community of developers sharing code, advice, and meaningful experiences

Try All Features of Camunda

Related Content

Achieve our first certification as a Camunda Certified Professional—Developer.
We've been working hard to reduce the job activation latency in Zeebe. Read on to take a peek under the hood at how we went about it and then verified success.
2023 was quite a year for Zeebe, and the team has been hard at work improving performance. Get an overview of all the latest technical improvements.