How to use external rest api in camunda

Hello,

I need to call the external rest-api in my workflow like for sending email or any other purpose
i tried the camunda examples and added service task for same with http-connector details for same,
But i’m getting the error

ENGINE-09005 Could not parse BPMN process. Errors:
One of the attributes ‘class’, ‘delegateExpression’, ‘type’, or ‘expression’ is mandatory on serviceTask. | resource external_api_task_sample.bpmn | line 22 | column 78 [ deploy-error ]

please find below BPMN file XML for same,

<?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:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0ds43ma" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.12.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.14.0">
  <bpmn:process id="Process_0c3r7ul" name="External Rest API check workflow" isExecutable="true" camunda:versionTag="v1">
    <bpmn:startEvent id="StartEvent_1" name="Rest API Task process">
      <bpmn:extensionElements>
        <camunda:formData>
          <camunda:formField id="TaskId" label="TaskId" type="long">
            <camunda:properties>
              <camunda:property id="Property_1jrj2p5" value="required" />
            </camunda:properties>
          </camunda:formField>
        </camunda:formData>
      </bpmn:extensionElements>
      <bpmn:outgoing>Flow_0htcwqu</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:sequenceFlow id="Flow_0htcwqu" sourceRef="StartEvent_1" targetRef="Activity_184u35t" />
    <bpmn:sequenceFlow id="Flow_177tm4x" sourceRef="Activity_184u35t" targetRef="Gateway_1qzbsow" />
    <bpmn:endEvent id="Event_1mhhkr8" name="End Process">
      <bpmn:incoming>Flow_1wu8owy</bpmn:incoming>
      <bpmn:incoming>Flow_1q6r96a</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:serviceTask id="Activity_184u35t" name="Calling External API Here">
      <bpmn:extensionElements>
        <camunda:connector>
          <camunda:inputOutput>
            <camunda:inputParameter name="headers">
              <camunda:map>
                <camunda:entry key="content-type">application/json</camunda:entry>
                <camunda:entry key="accept">application/json</camunda:entry>
              </camunda:map>
            </camunda:inputParameter>
            <camunda:inputParameter name="url">https://jsonplaceholder.typicode.com/todos/1</camunda:inputParameter>
            <camunda:inputParameter name="method">GET</camunda:inputParameter>
            <camunda:outputParameter name="completed">
              <camunda:script scriptFormat="Javascript">S(response).prop("completed");</camunda:script>
            </camunda:outputParameter>
          </camunda:inputOutput>
          <camunda:connectorId>http-connector</camunda:connectorId>
        </camunda:connector>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_0htcwqu</bpmn:incoming>
      <bpmn:outgoing>Flow_177tm4x</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:exclusiveGateway id="Gateway_1qzbsow" name="Task status decide">
      <bpmn:incoming>Flow_177tm4x</bpmn:incoming>
      <bpmn:outgoing>Flow_0i0dnmo</bpmn:outgoing>
      <bpmn:outgoing>Flow_1rxpkto</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:sequenceFlow id="Flow_0i0dnmo" name="Is Task Not Completed" sourceRef="Gateway_1qzbsow" targetRef="Activity_1ivxzyf">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${!completed}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_1rxpkto" name="Is Task Completed" sourceRef="Gateway_1qzbsow" targetRef="Activity_0ra90gy">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${completed}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_1wu8owy" sourceRef="Activity_0ra90gy" targetRef="Event_1mhhkr8" />
    <bpmn:sequenceFlow id="Flow_1q6r96a" sourceRef="Activity_1ivxzyf" targetRef="Event_1mhhkr8" />
    <bpmn:userTask id="Activity_0ra90gy" name="Completed Todo task confirmation" camunda:formKey="completedTaskForm">
      <bpmn:extensionElements>
        <camunda:formData>
          <camunda:formField id="FormField_2alondr" label="Completed task form" type="string">
            <camunda:properties>
              <camunda:property id="Property_2tha481" value="readonly" />
            </camunda:properties>
          </camunda:formField>
        </camunda:formData>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_1rxpkto</bpmn:incoming>
      <bpmn:outgoing>Flow_1wu8owy</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:userTask id="Activity_1ivxzyf" name="Todo Not Completed task confirmation" camunda:formKey="TaskNotCompletedTaskForm">
      <bpmn:extensionElements>
        <camunda:formData>
          <camunda:formField id="FormField_21mulvj" label="Task Not Completed task form" type="string" />
        </camunda:formData>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_0i0dnmo</bpmn:incoming>
      <bpmn:outgoing>Flow_1q6r96a</bpmn:outgoing>
    </bpmn:userTask>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0c3r7ul">
      <bpmndi:BPMNEdge id="Flow_1q6r96a_di" bpmnElement="Flow_1q6r96a">
        <di:waypoint x="530" y="360" />
        <di:waypoint x="600" y="360" />
        <di:waypoint x="600" y="265" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1wu8owy_di" bpmnElement="Flow_1wu8owy">
        <di:waypoint x="530" y="120" />
        <di:waypoint x="600" y="120" />
        <di:waypoint x="600" y="229" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1rxpkto_di" bpmnElement="Flow_1rxpkto">
        <di:waypoint x="380" y="222" />
        <di:waypoint x="380" y="120" />
        <di:waypoint x="430" y="120" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="323" y="146" width="54" height="27" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0i0dnmo_di" bpmnElement="Flow_0i0dnmo">
        <di:waypoint x="380" y="272" />
        <di:waypoint x="380" y="360" />
        <di:waypoint x="430" y="360" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="312" y="326" width="56" height="27" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_177tm4x_di" bpmnElement="Flow_177tm4x">
        <di:waypoint x="320" y="247" />
        <di:waypoint x="355" y="247" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0htcwqu_di" bpmnElement="Flow_0htcwqu">
        <di:waypoint x="188" y="247" />
        <di:waypoint x="220" y="247" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="152" y="229" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="137" y="272" width="70" height="27" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_1mhhkr8_di" bpmnElement="Event_1mhhkr8">
        <dc:Bounds x="582" y="229" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="497" y="237" width="63" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_1kh2ea1_di" bpmnElement="Activity_184u35t">
        <dc:Bounds x="220" y="207" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Gateway_1qzbsow_di" bpmnElement="Gateway_1qzbsow" isMarkerVisible="true">
        <dc:Bounds x="355" y="222" width="50" height="50" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="385" y="213" width="90" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_11qlwl8_di" bpmnElement="Activity_0ra90gy">
        <dc:Bounds x="430" y="80" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_1dc0ckv_di" bpmnElement="Activity_1ivxzyf">
        <dc:Bounds x="430" y="320" width="100" height="80" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

Please suggest any valid solution for this, Also if there is any other workaround to call the external Rest-api.

Hey @SC_94,

Which version and distro of Camunda are you using? I suspect that you might use Camunda Run? Currently Connectors are not working with Camunda Run out of the Box. You need to had the Connector lib to the Run distro.

I hope this helps
Nele

i’m using the camunda standalone server v7.16.0,
Is there any way to call external rest-api with service task or script task with javascript ?

If Yes, can you able to provide one working example for same

and thank you for the quick response

Hi @SC_94,

have a look at this post what you have to add: HTTP Connector in Camunda Run Distribution - #5 by rohanfarooqui

You can find the jars on maven central:
https://search.maven.org/artifact/org.camunda.bpm/camunda-engine-plugin-connect/7.16.0/jar
https://search.maven.org/artifact/org.camunda.connect/camunda-connect-connectors-all/1.5.2/jar
https://search.maven.org/artifact/org.camunda.connect/camunda-connect-core/1.5.2/jar

Hope this helps, Ingo

1 Like

Hi @SC_94,

this github repo explains all options of making REST calls from Camunda. If you don’t want to add dependencies to CamundaRun you can have a look there. It explains the script task, java delegate and external task worker as possible implementations. There is a script example with Groovy but it can be adopted to JavaScript. You can find an example bpmn for a JavaScript Task here.

Hope you can choose one of the options to make your project work.
Kind regards
Nele