How to: Use the K2 Workflow REST Feed with Microsoft Flow to Redirect a K2 Task

Exposing K2 workflow data through the Workflow REST API provides powerful integration with third party tools like Microsoft Flow. This topic shows you how to configure the service in Microsoft Flow, use the service to redirect a Task when that Task email arrives in an Outlook folder

These links take you directly to the scenarios. Make sure to read the Before you Begin section before following the steps in the scenarios:

Scenario - How to redirect a workflow Task in Microsoft Flow using an Outlook trigger

Before You Begin

If you have not done so already,

Then create a custom connector in Microsoft Flow using these steps:

  1. In Microsoft Flow, click on the settings icon and select Custom Connectors.
  2. Upload the swagger file saved from the K2 Workflow REST API page, and then add a description for this connector.
  3. Click on Continue.
  4. The Authentication type needed is Basic authentication. The swagger file pre-configures these settings. You can leave the authentication labels as they are.
  5. Click on Continue.
  6. The Definition tab loads information from the swagger file, so you can leave these values as they are.
  7. Click on Create Connector at the top of the Microsoft Flow page.
  8. Click on the plus sign of the K2 Workflow API custom connector.
  9. Enter the username and password configured for the K2 Workflow REST API service.
  10. Click on Create connection.
  11. The K2 Workflow REST API endpoint is now configured to be used in Microsoft Flow
Wait a few minutes after creating the connector and building your first flow. This allows the connector and its functions to appear and be selected in a new flow.

Scenario - How to redirect a workflow Task in Microsoft Flow using an Outlook trigger

In this scenario, you create a blank Microsoft Flow and configure it to start a K2 workflow when a K2 Task email is sent to a folder in Outlook, in this case a leave request email gets routed to the Leave Tasks folder in the HR inbox using an Outlook rule.

The workflow has been configured to send a custom notification that sets the email Subject to the serial number of the task. This is what Flow will use to identify which task gets redirected. In the subject of the notification email of the task within your workflow definition, use the taskSerialNumber field from the Workflow Context of the Context Browser within a Replace Inline Function to remove the SN= portion of the serial number object. Flow just needs the actual number.

High level steps

  1. Create a blank flow.
  2. Use the Outlook.com – When a new email arrives trigger.
  3. Select the K2 Workflow API - Task_Get as the first step of the action.
  4. Set the K2 Workflow API - Tasks_PostRedirectAction as the second step, configuring it to use the Subject of the email to provide the serialnumber
  5. Save your flow.
  6. Run your flow.

Detailed steps

  1. Open Microsoft Flow.
  2. Click Create from blank.
  3. Click Outlook.com and select When a new email arrives.
  4. If prompted, sign in to Outlook.com.
  5. Select the folder In this example it is the Leave Tasks folder. Outlook has an email rule that examines the body of an email for the words "Leave Request Task" and then moves that email into this folder.
  6. Click Add an action.
  7. Search for the K2 custom connector you created. Click K2 Workflow Api – Task_Get action.
  8. From the state drop down select Allocated.
  9. Click Add an action.
  10. Search for the K2 custom connector you created. Click K2 Workflow Api Preview – Task_PostRedirectAction action.
  11. Click theserialNumbertext box and select theAdd dynamic contentlink. Scroll down the Dynamic content list and selectSubject.
  12. Select theRedirectTotext box and enter the email address of the person that this task is redirected to.
  13. Click Save flow and you see a message stating your flow was created.
  14. Test the flow you created by starting the workflow. The task notification email (with the serial number of the task as the Subject) will arrive in the inbox and be routed to the Leave Tasks folder. That starts the flow and the task is redirected to the person configured in the RedirectTo text box.
K2 Cloud User Guide