Have you ever heard of K2 APIs? No importance because precisely in this article we will discover them together. From their activation to their connection to K2

Introduction to APIs

Before going further is what an API? In general, an API would be a clearly delimited facade by which an application offers its functionality (usually in the form of methods) to other applications. So in our case, these are the features that K2 offers. K2 has mainly 3 API categories. the APIs on:

  • Workflow
  • Smartobjects
  • the K2 server

That said, we are going for this article to discover only the Workflow REST API. This API gives us the possibility among other things to start a Workflow, to obtain the list of tasks, to obtain the diagram of a Workflow 😱. Great no? However, how do we activate it?

Enable Workflow REST API

Activation of the Workflow REST API is done on K2 Management: Integration -> APIs -> REST Workflow

API K2 - Enable API
After switching the control (activate the Workflow API) you must then click on the “Apply Changes” button. And now, we have activated the API.
API K2 - Apply Changes

For a quick overview of the methods exposed by this API, we will use Swagger

Testing K2 API with Swagger

In the same interface as before, we have a choice of 2 alternatives:

  • We copy the link and paste it in a browser of our choice
  • We directly open the link with the default browser of our machine

API K2 - Open Swagger

If everything went well so far you should this screen (if not post a message to report the problem

API K2 - Swagger Interface

To test a method we click on the category of the method and we have a list of methods that looks like the image below.

API K2 - Methods list

This view consists of the method names (and the names of its parameters) on the one hand and the description of the method on the other hand. A click on a method unfolds it and one can have all the details of which the most important are:

  • Parameters (values ​​expected by the method for its operation
  • Answer messages (or simply the results)

For example, for the Tasks Method, which provides the complete list of tasks (all instances of all workflows with all their associated information, there are no parameters.) Just execute (the Try it out! has the result (or answer)

API K2 - Example : Tasks

The answer has several parts

  • Curl
  • Body
  • Code
  • Headers

And of course what interests us here is Response Body: the content (body) of the result (of the answer)
In our server there is only one task as indicated by the following result:

API K2 - Result

Now how to create Smartoject from this API?

Creating Smartobjects from K2 API

To create Smartobjects, of course you have to create the Service Instance from the Service Type REST

We choose the Service Type (obviously REST) ​​then we fill a single value, that of the key Descriptor Location which is also mandatory. This is the full path to the API descriptor. In our case it is: https://k2.denallix.com/api/workflow/preview/swagger/docs

We do Next, then configure the display and system names of the Service Instance and we do Add

The Service Instance has been added successfully and we can now create our Smartobjects on it. For that it will be enough to make a right click on the ServiceObject which interests us in the Service Instance.

You know now, how to use K2 APIs. Stay connected because more detailed articles on using some of these SmartObjects are coming soon !


Leave a Reply to jayz Cancel reply

Your email address will not be published.