[Automation] Starting a K2 Workflow from UiPath

Level of Difficulty: Beginner – Senior.

UiPath has written an activity (UiPath.K2.Activities) that starts a K2 workflow. It seems quite simple at first; the only input properties that it expects are the service URL, username, password and workflow ID. It was ideal for what I was trying to achieve, until it wouldn’t load my workflows from the Service URL. My credentials were definitely correct as they worked with the API, so it had to be the Service URL. I tried multiple different permutations with no success before deciding to pivot to the API instead. So I’m sharing my workaround with you in case you are facing the same challenges I did.

What do we need to do to start a K2 workflow from UiPath?

All of the information that you need to get the HTTP Request working in UiPath can be obtained from Swagger, if it is available to you. To compile your Swagger URL, you’ll need to get your base K2 address and append /api/workflow/v1/swagger/index to it:


If there are multiple versions of the API you’re working with, substitute v1 with the latest version. You will need to obtain the following in order to make the HTTP Request:

  • The request URL (including the workflow ID)
  • The request body, which might differ slightly from mine
  • Authorised username and password

Getting Started

First thing first – let’s create a template text file that contains the body that we will be using for the HTTP Request:

Now, create a new UiPath project/sequence and make sure you install the UiPath.WebAPI.Activities package so that you are able to make HTTP requests:

Let’s put the sequence together using the following steps:

  1. Read the Template text file
  2. Replace the placeholder text with the actual values
  3. Compose the HTTP Request
  4. Print the status code

The sequence should look something like this:

Now let’s take a closer look at each step.

Read the Template text file

The template text file is stored in the same directory as the UiPath solution and is named ‘New Workflow Template.txt’:

Request Body Template Text File

Replace placeholder text with values

In this scenario, the text file contains the template text to be used as the request body to start the K2 workflow. The placeholders in this case are ‘<title>’ and ‘<value>’. These can be replaced using the string replace function to replace the placeholders with the actual values that should be sent through to start the workflow:

Replace placeholder text with values

Compose the HTTP Request

The most important part of getting an HTTP Request to work is making sure that the properties are correct. We need to set the following properties:

  • AcceptFormat = JSON
  • EndPoint = URL (the workflow API endpoint/URL, with the ID in the URL)
  • Method = POST
  • Body = NewWorkflowTemplate (the variable that stores the request body text)
  • BodyFormat = “application/json”
  • Password = Password (variable storing password – credentials used to auth on Swagger)
  • Username = Username (variable storing username – credentials used to auth on Swagger)
  • Headers = {Accept, In, String, “application/json”; Content-Type, In, String, “application/json”}:
HTTP Request Headers Assignment in UiPath

The output parameters may be set as well. In order to display the status code, it would need to be set to a variable. The properties of the HTTP request should be as follows:

HTTP request properties in UiPath

If you’d like to speed things up a little and change the solution presented in this post to work for your own use case, feel free to fork this GitHub repository and make the changes applicable to your use case. If you get stuck, please feel free to reach out or leave a comment below.

Published by Jacqui Muller

I am an application architect and part time lecturer by current professions who enjoys dabbling in software development, RPA, IOT, advanced analytics, data engineering and business intelligence. I am aspiring to complete a PhD degree in Computer Science within the next three years. My competencies include a high level of computer literacy as well as programming in various languages. I am passionate about my field of study and occupation as I believe it has the ability and potential to impact lives - both drastically and positively. I come packaged with an ambition to succeed and make the world a better place.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: