Create a Task¶
Tasks exist in the context of the service that provides the actions executed on it. Like repositories, the service name is part of the endpoint URL. For document creation, refer to the Create a Document use case.
Tasks are created by a POST request to the service endpoint URL. The request body contains the properties and metadata described in Tasks. Only the name property is mandatory.
Example - endpoint URL for creating a task in the operator-p4 service
/v1/services/operator-p4/tasks
The result is the created task including administrative properties such as the task ID (tid property) and the href URL.
Code Examples¶
Bash¶
Run the Create a Document example first and call the script with the returned href.
#!/bin/bash
if [ -z $1 ]; then
echo "Please call with href as parameter"
exit 0
fi
# !Assuming $TOKEN contains a valid JWT access token!
AUTH="Authorization: Bearer $TOKEN"
JSON="Content-Type:application/json"
# create print task for operator-p4 service
TASK=$(jq -c -n '{
"name":"My Task",
"metadata": {
"description": "Print task",
"Printer": "LocalPrinter"
},
"lists": {
"input": {
"embedded": {
"listItems": [
{
"href": "'$1'"
}
]
}
}
}
}')
RES=$(curl -k -s -X POST -H "$AUTH" -H "$JSON" -d "$TASK" "https://localhost:3008/v1/services/operator-p4/tasks")
TASKID=$(echo "$RES" | jq -r '.tid')
echo "Created task with taskId $TASKID"
JavaScript¶
Run the Create a Document example first and call the function with the returned href.
'use strict';
const request = require('request-promise-native');
const createTask = async function(token, href) {
// create print task for operator-p4 service
let req = {
url: 'https://localhost:3008/v1/services/operator-p4/tasks',
headers: {
Authorization: `Bearer ${token}`
},
body: {
name: 'My Task',
metadata: {
description: 'Print task',
Printer: 'LocalPrinter'
},
lists: {
input: {
embedded: {
listItems: [
{
href
}
]
}
}
}
},
resolveWithFullResponse: true,
json: true,
strictSSL: false
};
let res = await request.post(req);
const taskId = res.body.tid;
console.log(`Created task with taskId ${taskId}`);
};
Special Metadata Values¶
DPF Connector¶
For the DPF connector there is a special task metadata value DpfFileNameType to control the file name creation of the document within the DPF server's job directory. The value is only set for the respective task.
Available values:
-
uniqueEach file name is created by using a UUID version 4 string as base name followed by the document index and an extension, for example
5794d469-f734-4603-a00e-086af643dcf4_0.pdf. -
originalThe
nameproperty of the document is used as file name. The task creator is responsible for ensuring that the same document name is not used multiple times in the task input list.
Default: unique
Example
{
"name":"My DPF Task",
"panelType":"dpf4convert",
"metadata": {
"DpfFileNameType": "original"
},
"lists": {
"input": {
"embedded": {
"listItems": [
{
"href": "/v1/services/operator-fileupload/repo/<docId>"
}
]
}
}
}
}