How to: Use the K2 Workflow REST API with Microsoft Flow to Start a Workflow
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 use the service to start a workflow from SharePoint and Outlook.
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 1 - How to start a K2 workflow in Microsoft Flow using SharePoint
Scenario 2 - How to start a K2 workflow in Microsoft Flow using Outlook
Before You Begin
If you have not done so already,
- Enable the Workflow REST API in the K2 Management site. See Configuring the Workflow REST Service for more information about enabling the API.
- Create a custom connector to the K2 Workflow REST API in Microsoft Flow. See Create a custom connector in Microsoft Flow to call the K2 Workflow REST API for more information.
Scenario 1 - How to start a K2 workflow in Microsoft Flow using SharePoint
In this scenario, you configure Microsoft Flow to start a K2 workflow when a SharePoint list item is created. You create the flow using the Flow/SharePoint integration template. The K2 workflow used in this example has a data field configured in the process definition.
High-level steps
- Create a flow from SharePoint
- Select an action and then select and configure the K2 Workflow API - Start Workflow.
- Save your flow.
- Create a new item in the SharePoint list.
Detailed steps
- Open your SharePoint list or library.
- Click on the drown-down arrow next to Flow in the menu bar.
- In the Create a flow slide out, select See your flows.
- From the Start with one of these popular triggers page select When an item is created.
-
Paste your SharePoint Site Address in the Site Address text box, then from the List Name drop down select your list or library. In this scenario select the Employees list.
- Click + New Step.
- Search for the K2 custom connector you created and then select it. Note that you'll also see the K2 Workflow connector, allowing you to choose that one instead if you want to use basic authentication. Select the Start Workflow action.
- Click the Specify a workflow ID to start instance drop-down and choose the workflow to start.
In this scenario, select the New Employees workflow.
- Select the Dynamic content tab and drag the Name property field into the folio text box..
- Click Show advanced options and select the dataFields property (in this example the data field is EmployeeAddDate). Enter opening and closing quotes (" ") and select the space in the middle of the quotes. Select the Expression tab, locate and choose the utcNow() expression and click OK. This sets the content of the data field to the current time that this workflow gets started.
- Click Save flow and you see a message stating your flow was created.
- Open your SharePoint list or library and add a new item.
- Open the K2 Workflow > Instance tab in K2 Management to confirm that the workflow started.
Or check your worklist for the workflow item.
Scenario 2 - How to start a K2 workflow in Microsoft Flow using Outlook
In this scenario, you create a blank Microsoft Flow and configure it to start a K2 workflow when an email is sent to a folder in Outlook, in this case a leave request email gets routed to the Leave Request folder in the HR inbox using an Outlook rule. The K2 workflow used in this example has a data field configured in the process definition.
High level steps
- Create a blank flow.
- Use the Outlook.com – When a new email arrives trigger.
- Select and configure the K2 Workflow API - Start Workflow as the action.
- Save your flow.
- Run your flow.
Detailed steps
- Open Microsoft Flow.
- Click Create from blank.
- From the Start with one of these popular triggers page select When a new email arrives.
- If prompted, sign in to Outlook.com.
- Select the folder. In this example it is the Leave Requests folder. Outlook has an email rule that examines the body of an email for the words "Leave Request" and then moves that email into this folder.
- Click + New Step.
- Search for the K2 custom connector you created and then select it. Note that you'll also see the built-in K2 Workflow connector, allowing you to choose that one instead if you want to use basic authentication. Select the Start Workflow action.
- Click the Specify a workflow ID to start intance drop-down and choose the workflow to start when a new email arrives.
- Select the Dynamic content tab and drag the Subject property field into the folio text box.
- Click Show advanced options and select the Data Field property (in this example the data field is EmployeeAddDate). Enter opening and closing quotes (" ") and select the space in the middle of the quotes. Select the Expression tab, locate and choose the utcNow() expression and click OK. This sets the content of the data field to the current time that this workflow gets started.
- Click Save flow and you see a message stating your flow was created.
- Test the flow you created by sending a leave request email to the HR inbox.
- Open the K2 Workflow > Instance tab in K2 Management Site to confirm that the workflow started.
Or check your worklist for the workflow item.