HistoricalVehicleStatistics
- This method returns historical vehicle statistics records
-
Returns the following data:
- sourceId
- type (engine_state or odometer)
- timestamp (UTC timestamp)
- vehicle
- state (for engine_state)
Use Case
- Use to retrieve historical engine state and odometer records
Use an HTTP POST request to obtain historical vehicle statistics:
[POST] https://secure.trackyourtruck.com/WebApi/api/v2.2/HistoricalVehicleStatistics
Request Header
The request header should contain the API Access Token obtained from the authentication process. Get Access Token.
| Header Name | Description |
|---|---|
| Authorization | Access Token obtained from the 1st step's authentication process. |
Request Parameters
The Request should contain the following parameters:
| Parameter Name | Description | Value Format | Example |
|---|---|---|---|
| FromDateTime | Beginning Date/Time for your query* | MM/dd/yyyy hh:mm tt | 08/08/2018 05:00 AM |
| ToDateTime | Ending Date/Time for your query* | MM/dd/yyyy hh:mm tt | 08/08/2018 11:00 PM |
| VehicleId (Optional) | Filter by a specific VehicleID; "blank" returns all Vehicles | numeric | 825 |
| PageNumber (Optional) | Page number to return. Default: 1 | numeric | 1 |
| PageSize (Optional) | Number of records per page. Default: configured server value (100). Max: 1000 | numeric | 100 |
Create HistoricalVehicleStatistics Object
Below is the HistoricalVehicleStatistics request API examples:
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization","Bearer YOUR_API_TOKEN")
var content = new FormUrlEncodedContent(new []
{
new KeyValuePair<string, string>("FromDateTime", "08/08/2018 05:00 AM"),
new KeyValuePair<string, string>("ToDateTime", "08/08/2018 11:00 PM"),
new KeyValuePair<string, string>("VehicleId", "825"),
new KeyValuePair<string, string>("PageNumber", "1"),
new KeyValuePair<string, string>("PageSize", "100")
});
var response = await client.PostAsync("https://secure.trackyourtruck.com/WebApi/api/v2.2/HistoricalVehicleStatistics", content);
var responseString = await response.Content.ReadAsStringAsync();
//responseString will contain the response in JSON format
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Authorization","Bearer YOUR_API_TOKEN");
},
type: "POST",
url: "https://secure.trackyourtruck.com/WebApi/api/v2.2/HistoricalVehicleStatistics",
data: {
FromDateTime: "08/08/2018 05:00 AM",
ToDateTime: "08/08/2018 11:00 PM",
VehicleId: 825,
PageNumber: 1,
PageSize: 100
},
dataType: "json",
success: function(data){
//data object will contain the result as a JSON object
}
});
Sample HistoricalVehicleStatistics Object
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Authorization","Bearer YOUR_API_TOKEN");
},
type: "POST",
url: "https://secure.trackyourtruck.com/WebApi/api/v2.2/HistoricalVehicleStatistics",
data: {
FromDateTime: "08/08/2018 05:00 AM",
ToDateTime: "08/08/2018 11:00 PM",
VehicleId: 825,
PageNumber: 1,
PageSize: 100
},
dataType: "json",
success: function(data){
//data object will contain the result as a JSON object
}
});
A successful request will return the following JSON result:
{
"StatusCode": "200",
"Message": "OK",
"pagination": {
"PageNumber": 1,
"PageSize": 100,
"TotalRecords": 1250,
"TotalPages": 13,
"HasMore": true
},
"Results": [
{
"sourceId": "3438105744",
"type": "engine_state",
"timestamp": "2021-01-06T03:24:53.000Z",
"vehicle": "866",
"state": "on"
},
{
"sourceId": "3438105741",
"type": "engine_coolant_temperature",
"timestamp": "2025-01-06T03:24:53.000Z",
"vehicle": "865",
"temperature": 90
}
]
}
Test
Test the HistoricalVehicleStatistics using your AccessToken by entering it below:
Clicking the test button will send a request to the TYT API and display the result below.