K2 OOB REST & WCF Services

Hello Guys,

Today I’m going to explain a very interesting yet very useful topic which is nothing but K2 Out of the box Services. Have you ever got a chance to explore about them? If your answer is No then please go through this article and get the idea what exactly they are.

Services.png

Basically K2 have provided many out of the box services of all types like WCF Services, REST Services, which would serve us for many purposes as below

  • Start a workflow instance.
  • Get the worklist items.
  • Action a task.
  • Execute the smart object methods (SmartObject Services)

Let’s see how we enable these WCF and REST services.

We need to edit the web.config file located on K2 server at default location C:\Program Files (x86)\K2 blackpearl\WebServices\K2Services\web.config to enable the Workflow REST services.

In the config file we see 2 sections WCF and REST commented out. We just have to uncomment the sections which we would like to use and then restart K2 Blackpearl Service Instance

  • Now to start the workflow use below URL.
http://{K2Server}/k2services/REST.svc/Process/Definitions({WorkflowName})
/StartInstance?folio={FolioValue}

** Replace the {WorkflowName} with process full name 

  • See complete worklist Items assigned to you.
http://{K2Server}/k2services/REST.svc/Worklist/Items

** By default all the data will be retrieved in XML format, but you can specify parameter $Format= JSON to retrieve the data in JSON format

** Note:  It will show only the worklist items which are assigned to you.

  • Get worklist item details based on SN
http://{K2Server}/k2services/REST.svc/Worklist/Items({SN})?
pidatafield=true&actxmlfield=true

** Replace {SN} with SN value

  • Action a task using SN
http://{k2server}/k2services/REST.svc/Worklist/Items({SN})/Actions
({Action})/Execute

** {SN} needs to be replaced with SN number, {Action} needs to be replaced with workflow action

SmartObject Services

Now we will know about one more interesting feature which are known as K2 SmartObject Services. Each and every SmartObject that we create in K2 can be accessed as REST or WCF Endpoints using this feature.

Now we can enable these SmartObject Services by editing the K2HostServer.exe.config file, so when exposing a SmartObject as an endpoint it will be exposed on both WCF and REST service.

Now to see the all the Smart Object’s and its methods that are exposed as endpoints we can use below URL.

https://{K2Server}:{Port}/SmartObjectServices/endpoints/endpoints.xml

And below is the sample endpoint for a SmartObject

https://{K2Server}:{Port}/SmartObjectServices/rest/Vijay/
GetK2Worklist()/List?$format={format}&$top={top}&$skip={skip}
&filterXml={filterXml}&pUserName={pUserName}

SmartObject Name: Vijay
Method Name: GetK2Worklist()
Parameters: pUserName
$top, $format, filterXml, $skip – these are the default parameters that will be available in all endpoints.

$top – Gives you no. of records to be fetched from top of the list

$format – XML/JSON

$skip – skips no. of records from the list

Filterxml – used for filtering and sorting the list. Example below.

filterXml=<Criteria xmlns="http://schemas.k2.com/worklist/d1">
<Filter Field="ProcessFolio" Comparison="Like" ValueType="String">
Demo</Filter><Sort Field="ProcessStartDate" Order="Descending" />
</Criteria>

 

All the SmartObject parameters will be given as QueryParameters and the types of methods are Create, Read, Update, Delete, List, Execute.

That’s it, this is how we can use the OutoftheBox features that are available in K2

For more Help on exploring these things refer links below

WCF Services

https://help.k2.com/onlinehelp/k2blackpearl/DevRef/4.7/default.htm#WCF_Services.html

https://help.k2.com/onlinehelp/k2blackpearl/DevRef/4.7/default.htm#WorkflowWCFServicesSamples.htm

https://help.k2.com/onlinehelp/k2blackpearl/DevRef/4.7/default.htm#REST_Services.html

https://help.k2.com/onlinehelp/k2blackpearl/DevRef/4.7/default.htm#WorkflowWCFServices.htm%3FTocPath%3DRuntime%2520APIs%2520and%2520Services%7CWorkflow%7CWorkflow%2520WCF%2520services%7C_____0

SmartObject Services

https://help.k2.com/onlinehelp/k2blackpearl/DevRef/4.7/default.htm#REST_Services2.html

Advertisements

Author: Vijay

I'm a K2 Certified Developer, helping teams to automate, design, develop & maintain business process applications connecting across multiple platforms with multiple technologies.

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 )

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s