How to start a process via API

I am facing a new problem after finally being able to to deploy my custom process via the API. I was able to add my custom process to the /deployment endpoint of the API. Now I would like to start this process, but as far as I can tell, I have to add it to /process-definitions first, which I am unable to do. Can anyone tell me how to accomplish this?

My process definition (process.xml):

<?xml version="1.0" encoding="UTF-8"?>
<definitions id="Definition"
             namespace="http://www.example.org/MinimalExample"
             expressionLanguage="java"
             xmlns="https://www.omg.org/spec/BPMN/20100501/BPMN20.xsd"

  <process processType="Private" isExecutable="true" id="com.sample.HelloWorld" name="Hello World">
    <startEvent id="_1" name="StartProcess" />
    <scriptTask id="_2" name="Hello" >
      <script>System.out.println("Hello World");</script>
    </scriptTask>
    <endEvent id="_3" name="EndProcess" >
        <terminateEventDefinition/>
    </endEvent>
  </process>
</definitions>

This process has been assigned an ID in /deployment. How can I start this process via the API?

How did you build that model?
How have you setup Camunda?
How do you expect to do the deployment?

Hi @Niall.

I added the model to the deployment via an API query like this:
curl -X POST -F "deployment-name=hello-world" -F "enable-duplicate-filtering=false" -F "deploy-changed-only=false" -F "deployment-source=process application" -F "data=@process.xml" http://localhost:8080/engine-rest/deployment/create

My setup is just the demo setup, nothing more.

All I want is to be able to start that process. It should print “Hello World” once.

Well the model looks incorrect - are you not using the Camunda modeler to build it?

Have you tried starting it via the rest api?
https://docs.camunda.org/manual/latest/reference/rest/process-definition/post-start-process-instance/

Since I want to be able to upload a model via its xml representation, I did not use the Camunda Modeler to build it. What part looks incorrect about it?

I have tried, but I get a 404 - Not Found error. I suspect that is because my model has been added to /deployment but not to /process-definition.

The modeler generates the XML automatically - you can switch to on a tab at the bottom.
It’ll help you avoid syntax errors so i would suggest not building you model via XML if you can help it.

When you first deploy something it becomes a deployment - executable bpmn files are taken form the deployment and added to the process definitions at which point you can start them.

Most of it. It should looks something closer to this

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1m5nf7a" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.7.0">
  <bpmn:process id="Process_0l1esfv" name="doom" isExecutable="true">
    <bpmn:startEvent id="StartEvent_1">
      <bpmn:outgoing>Flow_1067kaf</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:sequenceFlow id="Flow_1067kaf" sourceRef="StartEvent_1" targetRef="Activity_1fh7vim" />
    <bpmn:endEvent id="Event_19msinj">
      <bpmn:incoming>Flow_02dn5mc</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_02dn5mc" sourceRef="Activity_1fh7vim" targetRef="Event_19msinj" />
    <bpmn:scriptTask id="Activity_1fh7vim" name="Run code" scriptFormat="javascript">
      <bpmn:incoming>Flow_1067kaf</bpmn:incoming>
      <bpmn:outgoing>Flow_02dn5mc</bpmn:outgoing>
      <bpmn:script>print('Some output')</bpmn:script>
    </bpmn:scriptTask>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0l1esfv">
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="179" y="79" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_1067kaf_di" bpmnElement="Flow_1067kaf">
        <di:waypoint x="215" y="97" />
        <di:waypoint x="270" y="97" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="Event_19msinj_di" bpmnElement="Event_19msinj">
        <dc:Bounds x="432" y="79" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_02dn5mc_di" bpmnElement="Flow_02dn5mc">
        <di:waypoint x="370" y="97" />
        <di:waypoint x="432" y="97" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="Activity_08hhrhd_di" bpmnElement="Activity_1fh7vim">
        <dc:Bounds x="270" y="57" width="100" height="80" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>
1 Like

Thanks @Niall for your help! I am going to try out the modeler now. Again, thanks a lot for your help!

Hey @Niall,

I have created a process via the Modeler now, it looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1wavkaa" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.7.0">
  <bpmn:process id="Process_1gxwbni" name="hello-world-process" isExecutable="true">
    <bpmn:startEvent id="StartEvent_1">
      <bpmn:outgoing>Flow_1795ect</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:sequenceFlow id="Flow_1795ect" sourceRef="StartEvent_1" targetRef="Activity_09vyoip" />
    <bpmn:scriptTask id="Activity_09vyoip" name="hello_world" scriptFormat="javascript">
      <bpmn:incoming>Flow_1795ect</bpmn:incoming>
      <bpmn:outgoing>Flow_12rghs9</bpmn:outgoing>
      <bpmn:script>print('Hello World')</bpmn:script>
    </bpmn:scriptTask>
    <bpmn:endEvent id="Event_1qbain7">
      <bpmn:incoming>Flow_12rghs9</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_12rghs9" sourceRef="Activity_09vyoip" targetRef="Event_1qbain7" />
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1gxwbni">
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="179" y="99" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_1795ect_di" bpmnElement="Flow_1795ect">
        <di:waypoint x="215" y="117" />
        <di:waypoint x="270" y="117" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="Activity_0gs8jzo_di" bpmnElement="Activity_09vyoip">
        <dc:Bounds x="270" y="77" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_1qbain7_di" bpmnElement="Event_1qbain7">
        <dc:Bounds x="432" y="99" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_12rghs9_di" bpmnElement="Flow_12rghs9">
        <di:waypoint x="370" y="117" />
        <di:waypoint x="432" y="117" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

The file is marked as executable, but it still is not added to the process definitions. Any idea what I’m doing wrong?

What exactly have you tried and what is the result you’re seeing?

I deployed the process using curl -X POST -F deployment-name=hello-world -F enable-duplicate-filtering=false -F deploy-changed-only=false -F deployment-source=process-application -F data=@payload_camunda.xml http://localhost:8080/engine-rest/deployment/create.

I can see the process is deployed by calling curl http://localhost:8080/engine-rest/deployment, which gives me the following output for this process:

{"links":[],"id":"c50efe5c-69c1-11ea-a526-08002722a417","name":"hello-world","source":"process-application","deploymentTime":"2020-03-19T10:12:34.392+0100","tenantId":null}

However, when I call curl http://localhost:8080/engine-rest/process-definition, the only processes mentioned are Invoice Receipt versions 1 and 2.

I was able to deploy the process without any problems, so there could be something wrong with your curl.
Have you tried just deploying via the modeler?
image

1 Like

That worked. Wow. Well, I still have to find out how to get the curl-query to the API to work though, but at least I know the definition is correct now. Thanks again for your help and your time @Niall!