Modify a Task Input List¶
After being created, the task has an input list which may be modified. Unless an input list have been specified in the request body when creating, the list is an empty array. With members, the list index starts at 0
.
Append a Document¶
New document references are appended to the input list by a POST request to the tasks input endpoint URL.
Unless metadata is required, the href
property is added to the endpoint URL as query parameter instead of a JSON request body.
Example - endpoint URL for appending a document with href /v1/services/operator-fileupload/repo/<docId>
to a task in the operator-p4
service with the task ID taskId
/v1/services/operator-p4/tasks/<taskId>/input?href=/v1/services/operator-fileupload/repo/<docId>
The result will be the created task list item including its index.
If metadata is required for the list item, the request body contains the properties and metadata for a list item as described in Lists. Only the href
property of the document is mandatory. Specifying both the href property as query parameter and in the request body is impossible.
Example - endpoint URL for appending a document to a task in the operator-p4
service with the task ID taskId
/v1/services/operator-p4/tasks/<taskId>/input
The result will be the created task list item including its index.
Delete a Document¶
A document contained in the input list is deleted by specifying its index number with a DELETE request to the input endpoint URL.
Example - endpoint URL for deleting the document with index index
from the input list of a task in the operator-p4
service with task ID taskId
/v1/services/operator-p4/tasks/<taskId>/input/<index>
The result will be HTTP status code 204 and no response body.
Code Examples¶
Bash¶
Run the Create a Task example first and call the script with the returned taskId
.
#!/bin/bash
if [ -z $1 ]; then
echo "Please call with taskId as parameter"
exit 0
fi
# !Assuming $TOKEN contains a valid JWT access token!
AUTH="Authorization: Bearer $TOKEN"
JSON="Content-Type:application/json"
# append a document to input list
# href is first command line parameter
ITEM=$(jq -c -n '{
"href":"'$1'",
"metadata": {
"name": "hello.txt",
"usage": "will be printed on a different printer",
"Printer": "OfficePrinter"
}
}')
# returns item with index 0
curl -k -s -X POST -H "$AUTH" -H "$JSON" -d "$ITEM" "https://localhost:3008/v1/services/operator-p4/tasks/$1/input" | jq .
# returns item with index 1
curl -k -s -X POST -H "$AUTH" -H "$JSON" -d "$ITEM" "https://localhost:3008/v1/services/operator-p4/tasks/$1/input" | jq .
JavaScript¶
Run the Create a Task example first and call the function with the returned taskId
.
'use strict';
const request = require('request-promise-native');
const modifyTaskInputList = async function(token, taskId) {
// append a document to input list
const req = {
url: `https://localhost:3008/v1/services/operator-p4/tasks/${taskId}/input`,
headers: {
Authorization: `Bearer ${token}`
},
body: {
href,
metadata: {
name: 'hello.txt',
usage: 'will be printed on a different printer',
Printer: 'OfficePrinter'
}
},
resolveWithFullResponse: true,
json: true,
strictSSL: false
}
let res = await request.post(req);
console.log(JSON.stringify(res.body, null, 2));
res = await request.post(req);
console.log(JSON.stringify(res.body, null, 2));
};