Skip to content

Modify a Task Input List


After being created, the task has an input list which may be modified. Unless an input list has 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 task's 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 is 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 is 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 is HTTP status code 204 and no response body.


Code Examples

Bash

Run the Create a Document and Create a Task examples first. Call the script with the returned taskId and document href.

#!/bin/bash

if [ -z $1 ] || [ -z $2 ]; then
  echo "Please call with taskId and href as parameters"
  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
# taskId is first, href is second command line parameter
ITEM=$(jq -c -n '{
  "href":"'$2'",
  "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 Document and Create a Task examples first. Call the function with the returned taskId and document href.

'use strict';

const request = require('request-promise-native');

const modifyTaskInputList = async function(token, taskId, href) {
  // 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));
};

Back to top