Discover the options available for integration between K2 and UiPathfor both inbound and outbound communication that allows you to make calls from K2 (via SmartObjects) to start processes in UiPath and how make calls from UiPath interact with K2 forms and workflows.

Requirements and Prerequisites

Requirements include:

  • K2 Five or later
  • K2 OAuth Extension for UiPath (attached)
  • UiPath API Swagger Definition
  • UiPath Orchestrator Tenant

Prerequisites include:

  • K2 Administrator privileges to configure a new service instance and OAuth resource
  • A familiarity with UiPath Orchestrator and Studio

In addition to the above requirements, you must have a basic understanding of REST-based web services, Swagger (OpenAPI), and Visual Basic (in UiPath Studio).

Setting up K2 to handle UiPath's API Requirements

The OAuth flow that allows you to call the UiPath APIs requires a custom OAuth extension to get a valid authorization token due to the way in which UiPath implements their authorization. UiPath requires that you specify your tenancy name, user name, and password as part of the body of the request to their API. This is different than the user-based OAuth consent flow that K2 handles out-of-the-box.

Step 1: Install the UiPath OAuth Extension

Extract the contents of the download available with this article and locate the SoureCode.Security.OAuth.Extensions.UiPath.dll. Copy it to the following location on your K2 Five server:

<install drive>:\Program Files or Program Files (x86)\K2\Host Server\Bin\OAuth\Extensions

Image

Step 2: Create an OAuth Resource Type

Use this step to add a new OAuth resource type.

  1. Open K2 Management with K2 Administrator privileges.
  2. Open the Authentication > OAuth > Resource Types node.
  3. Click New
  4. Specify the following information for the new resource type:
  • Name: UiPath
  • Description: A resource type for UIPath
  • Extension: SourceCode.Security.OAuth.Extensions.UIPath
  • Refresh Token Expiration: 0
  • Expiration Warning Days: 0
  • Invalid Message Delay Minutes: 0
  • Usage: Authorization

Your new resource type looks similar to the following:

Image

  1. Click OK to save your changes and note the new type on the Resource Types list.

Step 3: Add Resource Type Parameters

You need to add parameters to the UiPath resource type.

  1. Click to select the UiPath resource type which opens the Resource Type Parameters section.
  2. Click New on the parameters list and add the following parameters:
  • password
  • usernameOrEmailAddress
  • tenancyName

For each parameter check the Token Request option, and then click OK.

Image

Your parameters look similar to the following:

Image

Step 4: Create and Configure an OAuth Resouce

OAuth resources are instances of an OAuth resource type, and contain configuration values to provide authorization tokens for a system. For example, if you have two UiPath tenancies, you'd create two OAuth resources based on the type you created in step 2.

  1. In K2 Management browse to Authentication > OAuth > Resources, and then click New.
  2. Give it a name, such as UiPath - Test, select UiPath as the type, and specify a token endpoint (demo environments should use https://demo.uipath.com/api/account/authenticate

Image

  1. Click OK.
  2. Select the new resource and configure its parameters.
  3. Click New in the resource parameters list to specify a Token Value for each of the parameters, password, tenancyName, and usernameOrEmailAddress. These are the values you use for calling the UiPath API.

Image

Your page looks similar to the following and K2 is configured to communicate with UiPath.

Image

Architecture Overview

Use the following diagram and scenarios for discovering how to enable two-way communication between K2 and UiPath.

Image

Scenario 1: Use a K2 Form or Workflow to call UiPath

You typically use two main UiPath APIs, Queues and Jobs, in your K2 form or workflow. Use Queues to load a queue with work for a robot to process. Use Jobs to execute a process.

The name of the queue is defined in UiPath Orchestration. The name/value pairs that you need to send into the queue depend on how the UiPath process designer created it, so you'll need to know what these are before you can load a queue.

Use Jobs to start UiPath processes, which is different from how you start K2 processes/workflows. Loading a queue and starting a job is how you put a robot to work.

You call this API using an instance of the K2 REST service type, configured to use the UiPath OAuth resource and the attached Swagger descriptor.

  1. Browse to the K2 Management site and open Integration > Service Types.
  2. Find and select the REST service type and click New Instance.
  3. Give the instance a name, select OAuth as your Authentication Mode, and the UiPath OAuth resource as your OAuth Resource Name.
  4. Specify the full path and filename of your descriptor file for the Descriptor Location. Your page looks similar to the following:

Image

  1. Click OK and your service instance is created.
  2. Select the Service Instance node, find the UiPath service instance, and select it.
  3. Click Generate SmartObjects in the toolbar, and then click Select All on the Generate SmartObjects dialog. Then click OK

Image

You use the Add_Queue_Item method of the QueueItemResponse SmartObject to add items to the queue, and the StartJobs SmartObject to start a UiPath process. For more information about working with complex types, see Working with Endpoint SmartObjects: Serialization and DeserializationA Postman collection of the API calls is available for download to help you understand the requirements of the UiPath APIs and help test your solution.

Once you have your SmartObjects and you know how to use their methods, you can use these SmartObjects in SmartForms and workflow SmartObject events to integrate with UiPath.

Scenario 2: Calling the K2 REST API from UiPath to Start or Action a K2 Workflow

UiPath provides activities for working with REST-based services, including the K2 Workflow REST API which you can use to start and action K2 workflows from UiPath. To get started, make sure that UiPath Studio has the additional components installed to work with REST-based services. Once installed they can be found in the Activities library under Available > App Integration > Web > HTTP Request as pictured here:

Image

If you do not see the App Integration section, you may need to click the Refresh button to force the Activities panel to reload the available wizards, or you may need to install the UiPath.Web.Activities package. To check to see if your installation of UiPath has the package installed, click the package icon on the activities panel and look for UiPath.Web.Activities in the list. If it isn’t there, you can search and install it from the following window:

Image

You need the following UiPath activities to call the K2 Workflow REST API:

  • Get Transaction Item – This allows you to retrieve a queue item that was added to the queue by K2 or some other system.
  • Invoke Code – This activity allows you to use VB.NET string manipulation to create the request body that the K2 Workflow REST API expects to start or interact with a K2 workflow. Refer to K2 Workflow REST API for information on the format the JSON request body.
  • HTTP Request – Launch a wizard when dropped onto the UiPath canvas that allows you to configure the K2 Workflow REST API call, specifying values such as the endpoint URL, request method type, the response type, and the authentication. Use the Simple HTTP authentication method.

Image

Once you configure this, HttpClient activity appears on the UiPath process canvas. Select the activity and, in the Properties panel, set the value of the body property to the UiPath variable where you stored the request body you created using the Invoke Code activity. In this example, the JSON request is contained in a UiPath variable called K2Request.

Image

Once the K2 workflow is started, UiPath requires that you update the queue item transaction status so that future execution of the job doesn’t attempt to process the same queue item again.

The K2Example UiPath Process is provided for reference in the article download.

Additional Resources

Use the following resources to learn more about UiPath: