Versions Compared

Key

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

...

  • Example: Get the list of orders scheduled until a given date.
    • The attached example order_list_sample.sh is for use with curl. We do not consider curl to be perfect for handling 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
        JS7JS_URL="http://localhost:7446"
        
        # Identification of JS7 instance
        JS7JS_CONTROLLER_ID="testsuitecontroller"
        
        # Date up to that scheduled orders are returned
        JS7JS_DATE_DATETOTO="+1d"
        
        # Base64Authentication 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}"(default account)
        JS_USER=root
        JS_PASSWORD=root
        # -----------------------------------------
        
        
        # -----------------------------------------
        # Perform login
        echo ""
        echo "PERFORMING LOGIN"
        JS7JS_JSON="`curl$(curl -k -L -s -S -X POST -i -m 15 -H "Authorization: Basic $JS7_BASIC_AUTHENTICATION-user "$JS_USER:$JS_PASSWORD" -H "Accept: application/json" -H "Content-Type: application/json" $JS7$JS_URL/joc/api/authentication/login`"login)
        JS7JS_ACCESS_TOKEN=$(echo $JS7"$JS_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$JS_DATE_DATETOTO"
        # Execute web service request
        JS7JS_REST_BODY="{ \"controllerId\": \"$JS7$JS_CONTROLLER_ID\", \"compact\": true, \"dateTo\": \"$JS7$JS_DATE_DATETOTO\" }"
        JS7JS_JSON="`curl$(curl  -k -L -s -S -X POST -m 15 -d "$JS7$JS_REST_BODY" -i -m 15 -H "X-Access-Token: $JS7$JS_ACCESS_TOKEN" -H "Accept: application/json" -H "Content-Type: application/xml" $JS7$JS_URL/joc/api/orders`"orders)
        echo $JS7"$JS_JSON"
        # -----------------------------------------
        
        
        # -----------------------------------------
        # Perform logout
        echo ""
        echo "PERFORMING LOGOUT"
        curl -k -L -s -S -X POST -i -m 15 -H "X-Access-Token: $JS7$JS_ACCESS_TOKEN" -H "Accept: application/json" -H "Content-Type: application/json" $JS7$JS_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 which 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 the JOC Cockpit.
        • Line 22: Note the use of Basic HTTP authentication
        • Line 23: The request to the /authentication/login web service returns an access token which is used with further requests.
        • Line 32, 33: Note 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.

...