Discover the options available for integration between K2 and UiPath, for 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.
Table of Contents
Requirements and Prerequisites
- K2 Five or later
- K2 OAuth Extension for UiPath (attached)
The custom extension is included in K2 Five (5.2) and K2 Cloud Update 6 or later, so there is no need to install the custom OAuth extension if you have a version that includes it.
- UiPath API Swagger Definition
- UiPath Orchestrator Tenant
- 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
This extension is automatically installed with K2 Five (5.2) and later.
Step 2: Create an OAuth Resource Type
Use this step to add a new OAuth resource type.
- Open K2 Management with K2 Administrator privileges.
- Open the Authentication > OAuth > Resource Types node.
- Click New
- 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:
- 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.
- Click to select the UiPath resource type which opens the Resource Type Parameters section.
- Click New on the parameters list and add the following parameters:
For each parameter check the Token Request option, and then click OK.
Your parameters look similar to the following:
Step 4: Create and Configure an OAuth Resource
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.
- In K2 Management browse to Authentication > OAuth > Resources, and then click New.
- 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
- Click OK.
- Select the new resource and configure its parameters.
- 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.
Your page looks similar to the following and K2 is configured to communicate with UiPath.
Use the following diagram and scenarios for discovering how to enable two-way communication between K2 and UiPath.
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.
- Browse to the K2 Management site and open Integration > Service Types.
- Find and select the REST service type and click New Instance.
- Give the instance a name, select OAuth as your Authentication Mode, and the UiPath OAuth resource as your OAuth Resource Name.
- Specify the full path and filename of your descriptor file for the Descriptor Location. Your page looks similar to the following:
- Click OK and your service instance is created.
- Select the Service Instance node, find the UiPath service instance, and select it.
- Click Generate SmartObjects in the toolbar, and then click Select All on the Generate SmartObjects dialog. Then click OK.
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 Deserialization. A 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:
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:
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.
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.
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.
Use the following resources to learn more about UiPath: