How to: Use the K2 Workflow REST Feed 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 configure the service in Microsoft Flow, 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,

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 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

  1. Create a flow from SharePoint
  2. Select an action and then select and configure the K2 Workflow API - Start Workflow.
  3. Save your flow.
  4. Create a new item in the SharePoint list.

Detailed steps

  1. Open your SharePoint List or Library.
  2. Click on the drown-down arrow next to Flow in the menu bar.
  3. Under Create a flow select When a new item is added in SharePoint, complete a custom action.
  4. Flow displays the template you have selected and the permissions required to use the template. Click Continue.
  5. Give your flow a name, for example, New Employee, and then select New step.
  6. Click Add an action.
  7. Search for the K2 custom connector you created. Click K2 Workflow Api – Start Workflow action.
  8. Click the Workflow drop-down and choose the workflow to start when an item is added to the list.
  9. Click on Add dynamic content and drag the Name property from the Dynamic content fields into the folio text box.
  10. Click on Show advanced options and choose the Data Field property (in this example our Data Field is EmployeeAddDate). Enter opening and closing quotes (" ") and select the space in the middle of the quotes then click Add dynamic content. 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.
  11. Click Save flow and you see a message stating your flow was created.
  12. Open your SharePoint List or Library, and add a new item.
  13. 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

  1. Create a blank flow.
  2. Use the Outlook.com – When a new email arrives trigger.
  3. Select and configure the K2 Workflow API - Start Workflow as the action.
  4. Save your flow.
  5. 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.
  6. Click Add an action.
  7. Search for the K2 custom connector you created. Click K2 Workflow Api – Start Workflow action.
  8. Click the Workflow drop-down and choose the workflow to start when a new email arrives.
  9. Click on Add dynamic content and drag the Subject property from the Dynamic content fields into the folio text box.
  10. Click on Show advanced options and choose the Data Field property (in this example our Data Field is EmployeeAddDate). Enter opening and closing quotes (" ") and select the space in the middle of the quotes then click Add dynamic content. 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.
  11. Click Save flow and you see a message stating your flow was created.
  12. Test the flow you created by sending a leave request email to the HR inbox.
  13. Open the K2 Workflow > Instance tab in K2 Management Site to confirm that the workflow started.

    Or check your worklist for the workflow item.
K2 Cloud User Guide