Skip to content

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.


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 will be 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": "/v1/services/operator-fileupload/repo/'$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}`);
};

Back to top