Workflow REST API: Task Operations

The code snippets in this topic show how to perform common 'system' operations on workflow tasks, such as sleeping, waking, redirecting, allocating (opening) and releasing tasks.

Sleeping a task

Puts a specified task into a 'sleeping' state for a specific interval or until a specific date/time. Sleeping tasks do not appear on users' task lists by default. You can un-sleep a task with the Wake operation.

Copy

Sleeping a task

//use a System.Net.Http.HttpClient to send the request.
//TODO: You will have to construct the HttpClient and authentication for the webclient before running the snippet
System.Net.Http.HttpClient k2WebClient;

//the unique serial number of the task you want to sleep
string taskSerialNumber = "1_1";

//the interval to sleep the task for, in seconds
int sleepinterval = 60;

//construct the endpoint for the sleep operation (requires the task serial number). Your URL will likely be different.
string operationEndPoint = @"https://k2.denallix.com/api/workflow/v1/tasks/" + taskSerialNumber + @"/actions/sleep";

//construct the JSON for the input values (sleep duration/sleep until)
//format example {"SleepFor": 0,"SleepUntil": "2017-05-15T17:47:44.04Z"}
string requestBody = "{\"SleepFor\":" + sleepinterval.ToString() + "}";

System.Net.Http.StringContent operationHttpContent = new System.Net.Http.StringContent(requestBody, Encoding.UTF8, "application/json");
var requestResult = k2WebClient.PostAsync(operationEndPoint, operationHttpContent).Result;

Waking a task

'Wakes' a task that is currently sleeping so that the task will appear on a user's task list by default.

Copy

Waking a task

//use a System.Net.Http.HttpClient to send the request.
//TODO: You will have to construct the HttpClient and authentication for the webclient before running the snippet
System.Net.Http.HttpClient k2WebClient;

//the unique serial number of the task you want to wake
string taskSerialNumber = "1_1";

//construct the endpoint for the wake operation (requires the task serial number). Your URL will likely be different.
string operationEndPoint = @"https://k2.denallix.com/api/workflow/v1/tasks/" + taskSerialNumber + @"/actions/wake";

//send the request
var requestResult = k2WebClient.PostAsync(operationEndPoint, null).Result;

Opening (allocating) a task

Opening a task will assign/allocate the task to the authenticated user. If the task is assigned to a group and there is only one available 'slot' for the task, no-one else in the group will be able to open the task (unless the task owner releases the task again). Use this operation when someone will 'take ownership' of a task.

Copy

Opening (allocating) a task

//use a System.Net.Http.HttpClient to send the request.
//TODO: You will have to construct the HttpClient and authentication for the webclient before running the snippet
System.Net.Http.HttpClient k2WebClient;

//the unique serial number of the task you want to open
string taskSerialNumber = "1_1";

//construct the endpoint for the wake operation (requires the task serial number). Your URL will likely be different.
string operationEndPoint = @"https://k2.denallix.com/api/workflow/v1/tasks/" + taskSerialNumber + @"/actions/assign";

//send the request
var requestResult = k2WebClient.PostAsync(operationEndPoint, null).Result;

Releasing a task

If someone has opened a task, they can release the task so that the task is availabel for another user in the recipients configuration to open. Use this method if someone will release ownership of a task without completing the task.

Copy

Releasing a task

//use a System.Net.Http.HttpClient to send the request.
//TODO: You will have to construct the HttpClient and authentication for the webclient before running the snippet
System.Net.Http.HttpClient k2WebClient;

//the unique serial number of the task you want to release
string taskSerialNumber = "1_1";

//construct the endpoint for the wake operation (requires the task serial number). Your URL will likely be different.
string operationEndPoint = @"https://k2.denallix.com/api/workflow/v1/tasks/" + taskSerialNumber + @"/actions/release";

//send the request
var requestResult = k2WebClient.PostAsync(operationEndPoint, null).Result;

Redirecting a task to another user

Use this method to 'forward' a task to another user. Redirecting a task means the task is removed from the current user's task list and will appear on the other user's task list. Only task owners can redirect tasks.

Copy

Redirecting a task to another user

//use a System.Net.Http.HttpClient to send the request.
//TODO: You will have to construct the HttpClient and authentication for the webclient before running the snippet
System.Net.Http.HttpClient k2WebClient;

//the unique serial number of the task you want to redirect
//note: only someone who 'owns' the task can redirect the task
string taskSerialNumber = "1_1";

string operationEndPoint = TasksEndpointURI + @"/" + taskSerialNumber + @"/actions/redirect";
string redirectToUser = "K2:denallix\\codi";

//construct the JSON for the input values (redirect to)
//format example {"RedirectTo": "label:username"} or {"RedirectTo": "label:domain\\username"} (notice double backslash since this is required for escaping reserved JSON characters)
string requestBody = "{\"RedirectTo\":\"" + redirectToUser + "\"}";

System.Net.Http.StringContent operationHttpContent = new System.Net.Http.StringContent(requestBody, Encoding.UTF8, "application/json");
var requestResult = WebClient.PostAsync(operationEndPoint, operationHttpContent).Result;