Update the Travel Time of Activities

You can use the Core API to update the travel time of activities to meet specific business flows or to change the source of the travel data to estimate the travel time.

Let's look at an example to understand the use of updating the travel time.

Vision Corporation is a goods delivery company, which tracks the delivery of the goods in real-time and estimates the delivery time based on the real-time traffic. However, some goods might be delivered by other means such as helicopter or ferry. In this case, you can estimate the delivery time more accurately using the travel data of the helicopter or ferry from an external source.

Note:

You can update the travel time only for ordered or scheduled activities.

Update the Travel Time of an Activity

You can update the travel time of an activity using the 'Update an activity' operation as follows:

  1. Construct the request URL for the 'Update an activity' operation.
  2. Construct the request body with the setTravelTime parameter to specify the properties you want to update. In this scenario, you specify:
    • travelTime as 22
    • position as afterActivity
    • source as external
    • previousActivityId as 4225371
  3. Run the request using the PATCH HTTP method to update the travel time.

Note:

The setTravelTime function doesn't return an error if it can't change the travel time. For example, if another user moved the activity while you were sending the request, the travel time won't be updated. You must check whether the travelTime field is updated in the response.

Example cURL Command

Here's an example of the cURL command to update the travel time of an activity.

$ curl -X PATCH 'https://<instance_name>.etadirect.com/rest/ofscCore/v1/activities/4225372' -H 'Content-Type: application/json' --data-binary '{
     "setTravelTime": {
         "travelTime": 22,
         "position": "afterActivity",
         "source": "external",
         "previousActivityId": 4225371
     }
 }' -u 'clientID@instanceName:clientSecret'

Example Response

Here's an example of the response body in JSON format.

 
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
    "activityId": 4225372,
...skip
    "travelTime": 22,
...skip
}

Update the Travel Time of Multiple Activities

You can update the travel time of multiple activities in a single request using the 'Bulk update activities' operation as follows:

  1. Construct the request URL for the 'Bulk update activities' operation.
  2. Construct the request body with the activities parameter and updateParameters parameter to specify the properties of the multiple activities you want to update.
  3. Run the request using the POST HTTP method to update the travel time of multiple activities.

Note:

The setTravelTime function doesn't return an error if it can't change the travel time. For example, if another user moved the activity while you were sending the request, the travel time won't be updated. You must check whether the travelTime field is updated in the response.

Example cURL Command

Here's an example of the cURL command to update the travel time of multiple activities.
 
$ curl -X POST 'https://<instance_name>.etadirect.com/rest/ofscCore/v1/activities/custom-actions/bulkUpdate' -H 'Content-Type: application/json' --data-binary '{
     "updateParameters": {
         "identifyActivityBy": "apptNumber",
         "ifInFinalStatusThen": "doNothing",
         "ifExistsThenDoNotUpdateFields": ["resourceId"]
     },
     "activities": [
         {
             "apptNumber": "testApptNumber",
             "setTravelTime": {
                 "travelTime": 110,
                 "position": "first",
                 "source": "manual"
             }
         },
         {
             "apptNumber": "testApptNumber1",
             "setTravelTime": {
                 "travelTime": 220,
                 "position": "afterActivity",
                 "source": "external",
                 "previousActivity": {
                     "apptNumber": "testApptNumber"
                 }
             }
         }
    ]
 }' -u 'clientID@instanceName:clientSecret'

Example Response

Here's an example of the response body in JSON format.
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

 {
     "results": [
         {
             "operationsPerformed": [
                 "updateProperties"
             ],
             "activityKeys": {
                 "activityId": 4225371,
                "apptNumber": "testApptNumber",
                 "customerNumber": ""
             }
         },
         {
             "operationsPerformed": [
                 "updateProperties"
             ],
            "activityKeys": {
                 "activityId": 4225372,
                 "apptNumber": "testApptNumber1",
                 "customerNumber": ""
             }
         }
     ],
 }