Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The REST Web Service API is available from JOC Cockpit. When used by jobs then the jobs are required Use of the REST Web Service API requires jobs to implement a REST client implementing Client for the functionality to login and to logout from JOC Cockpit and any other calls to the API.

In order to reduce the overhead of REST client Client implementation a JavaScript class is suggested for simplified access to the JS7 REST Web Service by jobs JS7 - JavaScript Jobs.

REST Client JavaScript

...

Class

A JavaScript class is suggested that

  • connects to JOC Cockpit and performs sign-in login to JOC Cockpit for access to the JS7 REST Web Service API using
    • let api = new JS7RestApi(step)
  • performs calls to the JS7 REST Web Service API from the method
    • post(path, body)

For re-usability users can add the JavaScript class to a JS7 - Script Include that can be included in used by any number of jobs. Changes to the Script Include will be reflected with the next deployment of a workflow.

...

Find the source code of the REST Client JavaScript class:

  • The JavaScript class makes use of the Java ApiExecutor class that ships with JS7 Agents.
  • The class automatically signs in to JOC Cockpit from its constructor.
    • The JOC Cockpit URL, user account, password or certificate are used from the JS7 Agent's ./config/private/private.conf file.
    • For details see JS7 - JITL Common Authentication
  • The class automatically signs off from JOC Cockpit by use of its destructor.

...

A JavaScript job can make use of the REST Client JavaScript class provided by the Script Include:

  • The following syntax makes the JavaScript class available from a Script Include:
    • //!include JavaScript-JS7RestApi
  • The JavaScript class can be instantiated from by the job like this:
    • let api = new JS7RestApi(js7Step)
    • For use of the js7Step object see JS7 - Job API.

Download sample JavaScript job from Workflow (upload .json): pdJavaScriptJS7RestAPI.workflow.json

...

  • Line 1: references the Script Include to mail make the REST API JavaScript class available.
  • Line 3,5: implement the JavaScript job.
  • Line 7: creates an instance of the REST API Client JavaScript class that implicitly signs in to JOC Cockpit.
  • Line 9: executes a call to the JS7 REST Web Service that returns the current user's permissions in JOC Cockpit from the REST response.
  • Line 10,11: include examples for use of methods to retrieve the response body and HTTP status code.
  • Line 13,14: parses the JSON response body to access properties in the response.
  • Line 16: destructs the instance and implicitly signs out from JOC Cockpit.

...