Send Data to a REST API using IFS Workflow

In this post, I want to share my experience with another cool feature of IFS Cloud workflows, to make a REST call to an external API during a business transaction and read the response. Similar capability is there in the Event actions as well, but workflows bring new capabilities which are limited using event actions such as,

  • A workflow can read the API response and use it to modify business transaction
  • User can be notified with the API response or failures

In this article, we’ll see how to build a IFS Cloud workflow to send data to an external API and give a popup notification to the user with the API response.

  1. Prerequisites
  2. Business Scenario
  3. Creating the BPMN flow
    1. Get Customer Data
    2. Call the REST API
    3. User Message
  4. Projection Action
  5. Workflow in Action!
  6. Conclusion

Prerequisites

To simulate the API, I’m using a Postman mock server. If you are new to Postman, follow this link on how to setup a mock server.

Configure and use a Postman mock server

Below is my simple mock server which accepts a POST request and sends a response.

Response is a static json with following format

{
"apiResponse": "Record successfully created!"
}
Postman Mock Server

Copy the mock server URL which we’ll be using in the next steps when designing the workflow.

Business Scenario

We’ll use a simple business case to tryout the REST call capabilities of a workflow. Every time a Customer record is created or modified in IFS Cloud, we need to send the data to an external API, get the response and show a popup to the user with the response from the API.

Creating the BPMN flow

We’ll move on to create the workflow. for additional guidance on creating a workflow, please refer my previous blog post which explains more details on step by step guide to build a workflow. To create a new workflow,

  • Navigate to the Workflow page, and create a new workflow. Give a Process key and create.

Our workflow contains 3 simple steps.

  1. Retrieve the data using the keys included in the workflow input
  2. Call the REST API
  3. Display Message to the user
BPMN flow

Get Customer Data

To retrieve the data, we can use IFS Projection call type task. We can call the Same Projection and the entity set to get the data.

Call the REST API

To send the data to an external REST API, we can use IFS REST Call type task. We can create the payload to send to the mock server API using the values returned by the previous Projection call. In this example, I’m creating a simple payload with customerId and Name.

{
"CustomerId": "${CustomerId}",
"Name": "${Name}"
}

We can process the response from the API and use it in the next steps of our workflow. Our API sends a Json with attribute named apiResponse and I have added it to the _apiResponse key.

User Message

We can use the User Task task type to give a message to the user. I wish we could create a toast message since it’s only information to the user, but seems it’s not possible with workflows (yet). Please comment if you found a way to do this!

I have used the _apiResponse which we saved earlier as a form field so we can display the response from the API to the user.

After this, add an End event to finish the workflow execution.

Save and Deploy the latest version of your workflow.

Projection Action

Last step is to create the projection action to trigger the workflow.

In the workflow, Press + in the Projection Action Information and add the CustomerHandling as the Projection.

In the next step, choose Action Type as DATA and Entity Set Name as CustomerInfoSet

Since we need to send the data with each insert and update, check the actions.

Choose the Execution type as User Interaction and set Timing to After.

Enable the Projection action in the next step and Finish.

Workflow in Action!

Go to Customer page and create new/modify existing record. You should get a popup dialog with the response from the API!

API Response

Check the Postman Mock Server to verify if the payload received from IFS

Conclusion

Using IFS workflows, we could use extend from the outside capabilities to connect to other systems and build real-time integrations. This is a very useful feature which can be applicable in many business scenarios.

However, the IFS REST Call does nto provide advanced features like authentication, processing response headers and I found request, response json/xml handling is somewhat difficult and you need advanced scripting knowledge to create a complex payload or to process responses.

There’s no inbuilt logging feature for REST API calls and it’s hard to keep track of the API calls and the responses. I’m surprised by realizing that workflows are not using the IFS Connect to make the REST calls. It would be nice if it has been integrated with the IFS Connect similar to Event actions so it can utilize the IFS Connect capabilities as well.

My bottom line is, if you need to build a simple, real-time integration with another system, workflow if a great tool to use. If the integration requires great deal of processing and need to have a good visibility of the messages passed between the systems, better to do it as a customization involving IFS Connect.

Code

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL&quot; xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI&quot; xmlns:dc="http://www.omg.org/spec/DD/20100524/DC&quot; xmlns:camunda="http://camunda.org/schema/1.0/bpmn&quot; xmlns:di="http://www.omg.org/spec/DD/20100524/DI&quot; id="sample-diagram" targetNamespace="http://bpmn.io/schema/bpmn"&gt;
<bpmn:process id="TestWfSendToRestAPI" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_010w4hh</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:serviceTask id="Activity_1p3jku4" name="Send to REST API" camunda:class="com.ifsworld.fnd.bpa.delegate.IfsHttpConnectionDelegate">
<bpmn:extensionElements>
<camunda:inputOutput>
<camunda:inputParameter name="ifsBpaHttpConnectionMethod">POST</camunda:inputParameter>
<camunda:inputParameter name="ifsBpaHttpConnectionUrl">https://YOUR_MOCK_SERVER.mock.pstmn.io/PostmanPost</camunda:inputParameter&gt;
<camunda:inputParameter name="ifsBpaHttpConnectionBody">{
"CustomerId": "${CustomerId}",
"Name": "${Name}"
}</camunda:inputParameter>
<camunda:inputParameter name="ifsBpaHttpConnectionOutputs">
<camunda:map>
<camunda:entry key="_apiResponse">$.apiResponse</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:inputParameter name="ifsBpaHttpConnectionHeaders">
<camunda:map>
<camunda:entry key="Content-Type">application/json</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:inputParameter name="ifsBpaRestResponseVariableName">_Response</camunda:inputParameter>
<camunda:inputParameter name="ifsBpaRestResponseCheck" />
</camunda:inputOutput>
</bpmn:extensionElements>
<bpmn:incoming>Flow_19x44pc</bpmn:incoming>
<bpmn:outgoing>Flow_0gznou1</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_010w4hh" sourceRef="StartEvent_1" targetRef="Activity_1v77x97" />
<bpmn:serviceTask id="Activity_1v77x97" name="Get Customer Data" camunda:class="com.ifsworld.fnd.bpa.IfsProjectionDelegate">
<bpmn:extensionElements>
<camunda:inputOutput>
<camunda:inputParameter name="ifsBpaProjectionAction">READ</camunda:inputParameter>
<camunda:inputParameter name="ifsBpaProjectionETagVariableName">ETag</camunda:inputParameter>
<camunda:inputParameter name="ifsBpaProjectionName">CustomerHandling</camunda:inputParameter>
<camunda:inputParameter name="ifsBpaProjectionEntitySetName">CustomerInfoSet</camunda:inputParameter>
<camunda:inputParameter name="ifsBpaProjectionNestedEntityParameters">
<camunda:map />
</camunda:inputParameter>
<camunda:inputParameter name="ifsBpaProjectionParameters">
<camunda:map>
<camunda:entry key="CustomerId">${CustomerId}</camunda:entry>
</camunda:map>
</camunda:inputParameter>
</camunda:inputOutput>
</bpmn:extensionElements>
<bpmn:incoming>Flow_010w4hh</bpmn:incoming>
<bpmn:outgoing>Flow_19x44pc</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_19x44pc" sourceRef="Activity_1v77x97" targetRef="Activity_1p3jku4" />
<bpmn:sequenceFlow id="Flow_0gznou1" sourceRef="Activity_1p3jku4" targetRef="Activity_0xfznad" />
<bpmn:userTask id="Activity_0xfznad" name="User Information Message" camunda:formKey="User Message">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="_apiResponse" type="string">
<camunda:properties>
<camunda:property id="readonly" value="true" />
</camunda:properties>
</camunda:formField>
</camunda:formData>
<camunda:inputOutput>
<camunda:inputParameter name="ifsBpaImpl_apiResponse">
<camunda:map>
<camunda:entry key="en">API Response</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:inputParameter name="ifsBpaUserTaskIsHeader">true</camunda:inputParameter>
<camunda:inputParameter name="ifsBpaUserTaskHeaderLocale">
<camunda:map>
<camunda:entry key="en">API Response Message</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:inputParameter name="ifsBpaUserTaskIsCancel">true</camunda:inputParameter>
</camunda:inputOutput>
</bpmn:extensionElements>
<bpmn:incoming>Flow_0gznou1</bpmn:incoming>
<bpmn:outgoing>Flow_0ah0a30</bpmn:outgoing>
</bpmn:userTask>
<bpmn:endEvent id="Event_0nyxzct">
<bpmn:incoming>Flow_0ah0a30</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0ah0a30" sourceRef="Activity_0xfznad" targetRef="Event_0nyxzct" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="TestWfSendToRestAPI">
<bpmndi:BPMNEdge id="Flow_0ah0a30_di" bpmnElement="Flow_0ah0a30">
<di:waypoint x="750" y="254" />
<di:waypoint x="842" y="254" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0gznou1_di" bpmnElement="Flow_0gznou1">
<di:waypoint x="560" y="254" />
<di:waypoint x="650" y="254" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_19x44pc_di" bpmnElement="Flow_19x44pc">
<di:waypoint x="390" y="254" />
<di:waypoint x="460" y="254" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_010w4hh_di" bpmnElement="Flow_010w4hh">
<di:waypoint x="218" y="254" />
<di:waypoint x="290" y="254" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="182" y="236" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_04gi2g3_di" bpmnElement="Activity_1p3jku4">
<dc:Bounds x="460" y="214" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_14bzm72_di" bpmnElement="Activity_1v77x97">
<dc:Bounds x="290" y="214" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0ltv0o5_di" bpmnElement="Activity_0xfznad">
<dc:Bounds x="650" y="214" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0nyxzct_di" bpmnElement="Event_0nyxzct">
<dc:Bounds x="842" y="236" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

16 thoughts on “Send Data to a REST API using IFS Workflow

Add yours

  1. According to your screenshot of Projection Action Configuration setting, it is not available in my side. Check this screencast : Video

      1. Could not figure out which Cloud Version it is but i found below information :

        IFS Aurena framework version: 21.2.16.20230104083914.0

        IFS Aurena client version: 21.2.16.20230104083914.0

        IFS OData provider version: 21.2.16.20230104105134.0

      2. Current Version is 21R2

        IFS Aurena framework version: 21.2.16.20230104083914.0

        IFS Aurena client version: 21.2.16.20230104083914.0

        IFS OData provider version: 21.2.16.20230104105134.0

      3. Hi Mukesh,

        As I aware workflow trigger using projection action was added in 22R1 or 22R2. Unfortunately it’s not available in 21RX. I believe you could do the same using event action as well. Then the trigger can be configured for CustomerInfo Entity and hope you can do the same workflow.

Leave a reply to Mukesh Cancel reply

Website Powered by WordPress.com.

Up ↑