Versions Compared

Key

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

...

  • Example: Suspend an order.
    • The attached example order_suspend_sample.sh is 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
        JS7JS_URL="http://localhost:7446"
        
        # Identification of JS7 instance
        JS7JS_CONTROLLER_ID="testsuitecontroller"
        
        # ID of order that should be suspended
        JS7JS_ORDER_ID="#2021#2024-0306-20#T623271738230#P44126285211-rootdaily"
        
        # 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-user "Authorization: Basic $JS7_BASIC_AUTHENTICATION$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 \" )
        # -----------------------------------------
        
        
        # -----------------------------------------
        # Suspend a specific order identified by its ID
        echo ""
        echo "SUSPENDING ORDER WITH ID: $JS7$JS_ORDER_ID"
        JS7JS_REST_BODY="{ \"controllerId\": \"$JS7$JS_CONTROLLER_ID\", \"orderIds\": [ \"$JS7$JS_ORDER_ID\" ] }"
        echo "Request Body: $JS7$JS_REST_BODY"
        # Execute web service request
        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/json" $JS7$JS_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$JS_ORDER_ID"
        # Execute web service request
        JS7JS_REST_BODY="{ \"controllerId\": \"$JS7$JS_CONTROLLER_ID\", \"compact\": true, \"orderIds\": [ \"$JS7$JS_ORDER_ID\" ] }"
        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 "Request Body: $JS7$JS_REST_BODY"
        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 31: Suspending an order includes specifying 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 waiting a few seconds include repeated checking 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.

...