Triggering a K2 Workflow from Microsoft Flow.

In this Post we shall see how we can trigger a K2 workflow from a Microsoft flow.

We have 2 ways to do this.

  • Using the K2 connector.
  • Using the OOB K2 Api.

Using the K2 connector

  • Go to Microsoft flow Dashboard and click on “New” and you will see few options among which you need to select “Instant – from blank”.
  • Give your flow a name and there you will find different options to trigger this flow. Here I have selected “Manually trigger a flow”.
  • Once the flow designer opens, Click on New Step in the search box and type K2 which will show you the K2 related connectors. Select the K2 Workflow connector as shown in below.
  • Select Start Workflow from the list shown.
  • Next provide the details of your workflow, you can pass either Workflow Id or workflow name here or you can select from the list.

Now create a new connection by clicking on dots and select New Connection

Enter data and click create which will create a new K2 connection and use it for this step.

** This Connector that we are using here is a preview K2 Connector version which uses a single user account credentials which we need to use only for development Purpose. But in general UAT and production environment we have to create a Custom Connector which uses Oauth to authenticate.

To Know about Creating K2 Custom Connector please visit the link below

https://help.k2.com/kb002870

  • Once you select the workflow it will provide options to pass folio, data fields  and some advanced options as shown in below screengrab
  • Click on Save and then Click on Test and Select I’ll Perform the trigger Action
  • Once flow Started Successfully, we can go “My Flows” and tab and select the flow that we have created and click on dots Symbol and select Run history to see the status of the flow instance that we have started.

Here the Flow instance status shows as Test Succeeded which means the flow has run successfully and it should have created an instance in K2. Let’s go to K2 Management Site and see if it has created an instance.

You can see the instance has been created successfully. Let’s see the other approach using K2 api.

Using the OOB K2 Api.

  • Enable K2 REST Api from K2 Management (Use below link to know how)

https://help.k2.com/onlinehelp/K2Five/UserGuide/current/default.htm#K2-Management-Site/Integration/Workflow-REST-API.htm

  • Once enabled check whether they are configured properly or not by running below url in post man or directly in chrome browser.

https://servername/Api/Workflow/V1/workflows

If we see the data then we are good to go.

  • Go to Microsoft flow designer -> navigate to my flows – > select the flow that we created before -> click edit -> add new step -> Search for HTTP and select.
  • Enter the Requests details as shown in below.

You can know the Workflow Id of your process from the “Process” smartobject which will be under category System/Management/Workflows/Smartobjects

  • Set the Headers Content-Type as Application/Json.
  • In Body we can set the Folio and data fields as shown.
  • Authentication we can user Basic/OAuth. Here I’m using Basic for Development purpose but generally we have to set it to OAuth. To know how to set OAuth for Api please refer below link https://help.k2.com/kb002784

Save the flow and test run to see the result.

**Similarly we can follow the same approach performing a task action and other K2 Activities.

That’s it. This is how we can trigger a K2 workflow from Microsoft flow. Thanks for Reading!!