Versions Compared

Key

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

...

  • The REST Web Service API is called by using an HTTP client that sends JSON based requests and that receives JSON based responses.
  • The following REST Web Service API requests are supportedavailable:
    • URL joc/api/authentication/login
    • URL  joc/api/* 
      • Subsequent calls to URLs can e.g. for example retrieve the inventory and current information about workflows and ordersof workflow.
      • Find the respective URLs from the Technical Documentation of the REST Web Service API
      • The JS7 REST Web Service API will return returns the respective JSON response indicated with the docs.
    • URL joc/api/authentication/logout
      • The last operation of a client should be is a call to this URL in order to logout from the REST Web Service API.
  • Requirements
    • REST Web Service API requests should use HTTP POST or GET operations as indicated.
    • Should an the idle timeout of 15 minutes between two web service requests be exceeded then the current session is invalidated and exceed the JOC Cockpit session timeout then a login has to be performed. The timeout value can be adjusted with shiro.ini.

Examples

  • Example: Get the list of orders scheduled until a given date
    • Find attached example order_list_sample.sh for use with curl. We do not consider curl to be perfectly prepared to handle web service requests, however, it shows the building blocks:
      • Code Block
        languagebash
        titleExample for use with curl to get list of orders scheduled until a given date
        linenumberstrue
        collapsetrue
        #!/bin/sh
        # ----------------------------------------
        # Protocol, host and port of JOC Cockpit
        JS7_URL="http://localhost:7446"
        
        # Identification of JS7 instance
        JS7_CONTROLLER_ID="testsuite"
        
        # Date up to that scheduled orders are returned
        JS7_DATETO="+1d"
        
        # Base64 encoded string "user:password" for authentication. The below string represents "root:root"
        JS7_BASIC_AUTHENTICATION="`echo "root:root" | base64`"
        JS7_BASIC_AUTHENTICATION="${JS7_BASIC_AUTHENTICATION:0:${#JS7_BASIC_AUTHENTICATION}-4}"
        # -----------------------------------------
        
        
        # -----------------------------------------
        # Perform login
        echo ""
        echo "PERFORMING LOGIN"
        JS7_JSON="`curl -k -s -S -X POST -i -m 15 -H "Authorization: Basic $JS7_BASIC_AUTHENTICATION" -H "Accept: application/json" -H "Content-Type: application/json" $JS7_URL/joc/api/authentication/login`"
        JS7_ACCESS_TOKEN=$(echo $JS7_JSON | grep -Po '"accessToken":.*?[^\\]"' | awk -F ':' '{print $2}' | tr -d \" )
        # -----------------------------------------
        
        
        # -----------------------------------------
        # Get the list of orders for a date range
        echo ""
        echo "Get the list of orders for date range: $JS7_DATETO"
        # Execute web service request
        JS7_REST_BODY="{ \"controllerId\": \"$JS7_CONTROLLER_ID\", \"compact\": true, \"dateTo\": \"$JS7_DATETO\" }"
        JS7_JSON="`curl -k -s -S -X POST -d "$JS7_REST_BODY" -i -m 15 -H "X-Access-Token: $JS7_ACCESS_TOKEN" -H "Accept: application/json" -H "Content-Type: application/xml" $JS7_URL/joc/api/orders`"
        echo $JS7_JSON
        # -----------------------------------------
        
        
        # -----------------------------------------
        # Perform logout
        echo ""
        echo "PERFORMING LOGOUT"
        curl -k -s -S -X POST -i -m 15 -H "X-Access-Token: $JS7_ACCESS_TOKEN" -H "Accept: application/json" -H "Content-Type: application/json" $JS7_URL/joc/api/authentication/logout
        # -----------------------------------------
        echo ""
        
      • Explanations

        • Line 4: Depending on your JOC Cockpit installation the protocol will be http or https. The default port is 4446 but might have been modified during setup.
        • Line 7: The Controller ID is specified during installation of the Controller and identifies a Controller standalone instance or a Controller cluster.
        • Line 10: Specify the relative date up to that you want the list of scheduled orders to be returned.
        • Line 13, 14: Default credentials after installation include the account "root" and password "root". The credentials might have been changed after setup of JOC Cockpit.
        • Line 22: Consider to use Basic HTTP authentication
        • Line 23: The request to the /authentication/login web service returns an access token that is used with further requests.
        • Line 32, 33: Consider the JSON body created for the request and the URL including the path /joc/api/orders used to return order information.
        • Line 42: Always perform a logout and consider the session idle timeout.
  • Example: Suspend an order
    • Find attached example order_suspend_sample.sh for use with curl. We do not consider curl to be perfectly prepared to handle web service requests, however, it shows the building blocks:
      • Code Block
        languagebash
        titleExample for use with curl to suspend an order
        linenumberstrue
        collapsetrue
        #!/bin/sh
        # ----------------------------------------
        # Protocol, host and port of JOC Cockpit
        JS7_URL="http://localhost:7446"
        
        # Identification of JS7 instance
        JS7_CONTROLLER_ID="testsuite"
        
        # ID of order that should be suspended
        JS7_ORDER_ID="#2021-03-20#T6232717382-root"
        
        # Base64 encoded string "user:password" for authentication. The below string represents "root:root"
        JS7_BASIC_AUTHENTICATION="`echo "root:root" | base64`"
        JS7_BASIC_AUTHENTICATION="${JS7_BASIC_AUTHENTICATION:0:${#JS7_BASIC_AUTHENTICATION}-4}"
        # -----------------------------------------
        
        
        # -----------------------------------------
        # Perform login
        echo ""
        echo "PERFORMING LOGIN"
        JS7_JSON="`curl -k -s -S -X POST -i -m 15 -H "Authorization: Basic $JS7_BASIC_AUTHENTICATION" -H "Accept: application/json" -H "Content-Type: application/json" $JS7_URL/joc/api/authentication/login`"
        JS7_ACCESS_TOKEN=$(echo $JS7_JSON | grep -Po '"accessToken":.*?[^\\]"' | awk -F ':' '{print $2}' | tr -d \" )
        # -----------------------------------------
        
        
        # -----------------------------------------
        # Suspend a specific order identified by its ID
        echo ""
        echo "SUSPENDING ORDER WITH ID: $JS7_ORDER_ID"
        JS7_REST_BODY="{ \"controllerId\": \"$JS7_CONTROLLER_ID\", \"orderIds\": [ \"$JS7_ORDER_ID\" ] }"
        echo "Request Body: $JS7_REST_BODY"
        # Execute web service request
        curl -k -s -S -X POST -d "$JS7_REST_BODY" -i -m 15 -H "X-Access-Token: $JS7_ACCESS_TOKEN" -H "Accept: application/json" -H "Content-Type: application/json" $JS7_URL/joc/api/orders/suspend
        echo ""
        echo ""
        echo "... sleep 3 seconds to check results"
        sleep 3
        # -----------------------------------------
        
        
        # -----------------------------------------
        # Get order state information
        echo ""
        echo "GETTING STATE INFORMATION FOR ORDER WITH ID: $JS7_ORDER_ID"
        # Execute web service request
        JS7_REST_BODY="{ \"controllerId\": \"$JS7_CONTROLLER_ID\", \"compact\": true, \"orderIds\": [ \"$JS7_ORDER_ID\" ] }"
        JS7_JSON="`curl -k -s -S -X POST -d "$JS7_REST_BODY" -i -m 15 -H "X-Access-Token: $JS7_ACCESS_TOKEN" -H "Accept: application/json" -H "Content-Type: application/xml" $JS7_URL/joc/api/orders`"
        echo "Request Body: $JS7_REST_BODY"
        echo $JS7_JSON
        # -----------------------------------------
        
        
        # -----------------------------------------
        # Perform logout
        echo ""
        echo "PERFORMING LOGOUT"
        curl -k -s -S -X POST -i -m 15 -H "X-Access-Token: $JS7_ACCESS_TOKEN" -H "Accept: application/json" -H "Content-Type: application/json" $JS7_URL/joc/api/authentication/logout
        # -----------------------------------------
        echo ""
        
    • Explanations
      • Line 31: Suspending an order includes to specify the Controller ID and an array of order IDs..
      • Line 38: The operation to suspend an order works asynchronously as the request is forwarded to the Controller and from the Controller to the Agent that holds the order. More elaborate solutions to wait for completion of an suspend operation than just to wait a few seconds include to repeatedly check the order state.
      • Line 47: The request to retrieve the order state information is sent to the /joc/api/orders URL.
      • Line 58: Always perform a logout and consider the session idle timeout.

...

languagebash
titleExample for use with curl to run a number of orders for a given set of workflows
collapsetrue

...

Examples

Find examples from JS7 - How to access the REST Web Service API from the Shell.