Commute Truecost | Climes API
Commute truecost endpoint allows user to calculate the truecost value for their entire journey with different types of vehicles for different distances through their journey.
Request Parameters
Request Schema
This is the schema for the commute truecost api. Each request payload requires queries
Queries Schema
Each queries
object has a legs
array which requires individual leg object.
Name Description | Type | Optional | |
---|---|---|---|
legs | The legs denote the individual method of travel done via any of the vehicle type. | array | required |
Leg Schema
Name Description | Type | Optional | |
---|---|---|---|
commute_method | This is the type of vehicle used for the travel over that much distance. Enums : TRAIN AUTO INTRACITY_BUS CAB BIKE_COMMUTER BIKE_SPORTS BIKE_CRUISER CAR_HATCHBACK_ELECTRIC CAR_HATCHBACK_CNG CAR_HATCHBACK_DIESEL CAR_HATCHBACK_PETROL CAR_SEDAN_ELECTRIC CAR_SEDAN_CNG CAR_SEDAN_PETROL CAR_SEDAN_DIESEL CAR_SUV_ELECTRIC CAR_SUV_CNG CAR_SUV_PETROL CAR_SUV_DIESEL | string | required |
commute_distance | The total distance traveled using that particular commute_method . | number | optional |
Endpoint
/v3/commute
Method
POST
Headers
{
'x-api-key': 'API_KEY',
'Content-Type': 'application/json'
}
Payload
{
"queries": {
"legs": [
{
"commute_method": "TRAIN",
"commute_distance": 50
},
{
"commute_method": "AUTO",
"commute_distance": 50
},
{
"commute_method": "INTRACITY_BUS",
"commute_distance": 50
},
{
"commute_method": "CAB",
"commute_distance": 50
},
{
"commute_method": "BIKE_COMMUTER",
"commute_distance": 50
},
{
"commute_method": "BIKE_SPORTS",
"commute_distance": 50
},
{
"commute_method": "BIKE_CRUISER",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_DIESEL",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_DIESEL",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_DIESEL",
"commute_distance": 50
}
]
}
}
Response Parameters
Response Schema
Name | Description | Type |
---|---|---|
message | A human readable string describing response for the given request. | string |
truecost | This object contains the calculated truecost values in tonnes CO2e for the request. | object |
total_truecost | This contains total truecost for all the legs in tonnes CO2e for the request. | number |
legs_truecost | This object contains the calculated truecost values for each leg in tonnes CO2e. It is same order as the request. | object |
The error message is for your information, not the end users.
Please use the status codes and communicate the error to user accordingly
The API returns the first validation error that is encountered even if there are multiple errors with the request
Status Code
200
Response Data
The response will contain the truecost values in tonnes CO2e for each commute_method
as per the request order respectively.
{
"message": "Truecost calculated successfully",
"truecost": {
"total_truecost": 2.337,
"legs_truecost": {
"TRAIN": 0.123,
"AUTO": 0.123,
"INTRACITY_BUS": 0.123,
"CAB": 0.123,
"BIKE_COMMUTER": 0.123,
"BIKE_SPORTS": 0.123,
"BIKE_CRUISER": 0.123,
"CAR_HATCHBACK_ELECTRIC": 0.123,
"CAR_HATCHBACK_CNG": 0.123,
"CAR_HATCHBACK_DIESEL": 0.123,
"CAR_HATCHBACK_PETROL": 0.123,
"CAR_SEDAN_ELECTRIC": 0.123,
"CAR_SEDAN_CNG": 0.123,
"CAR_SEDAN_PETROL": 0.123,
"CAR_SEDAN_DIESEL": 0.123,
"CAR_SUV_ELECTRIC": 0.123,
"CAR_SUV_CNG": 0.123,
"CAR_SUV_PETROL": 0.123,
"CAR_SUV_DIESEL": 0.123
}
}
}
Here the response will be in the same order as the request values.
Sample Request
- cURL
- NodeJs
- Axios
- Python
- Php
curl --location --request POST 'BASE_URL/v3/commute'
--header 'x-api-key: API_KEY'
--header 'Content-Type: application/json'
--data-raw '{
"queries": {
"legs": [
{
"commute_method": "TRAIN",
"commute_distance": 50
},
{
"commute_method": "AUTO",
"commute_distance": 50
},
{
"commute_method": "INTRACITY_BUS",
"commute_distance": 50
},
{
"commute_method": "CAB",
"commute_distance": 50
},
{
"commute_method": "BIKE_COMMUTER",
"commute_distance": 50
},
{
"commute_method": "BIKE_SPORTS",
"commute_distance": 50
},
{
"commute_method": "BIKE_CRUISER",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_DIESEL",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_DIESEL",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_DIESEL",
"commute_distance": 50
}
]
}
}'
const fetch = require('node-fetch');
const url = 'BASE_URL/v3/commute';
const apiKey = 'API_KEY';
const headers = {
'x-api-key': apiKey,
'Content-Type': 'application/json'
};
const body = JSON.stringify({
queries: {
legs: [
{
commute_method: 'TRAIN',
commute_distance: 50
},
{
commute_method: 'AUTO',
commute_distance: 50
},
{
commute_method: 'INTRACITY_BUS',
commute_distance: 50
},
{
commute_method: 'CAB',
commute_distance: 50
},
{
commute_method: 'BIKE_COMMUTER',
commute_distance: 50
},
{
commute_method: 'BIKE_SPORTS',
commute_distance: 50
},
{
commute_method: 'BIKE_CRUISER',
commute_distance: 50
},
{
commute_method: 'CAR_HATCHBACK_ELECTRIC',
commute_distance: 50
},
{
commute_method: 'CAR_HATCHBACK_CNG',
commute_distance: 50
},
{
commute_method: 'CAR_HATCHBACK_DIESEL',
commute_distance: 50
},
{
commute_method: 'CAR_HATCHBACK_PETROL',
commute_distance: 50
},
{
commute_method: 'CAR_SEDAN_ELECTRIC',
commute_distance: 50
},
{
commute_method: 'CAR_SEDAN_CNG',
commute_distance: 50
},
{
commute_method: 'CAR_SEDAN_PETROL',
commute_distance: 50
},
{
commute_method: 'CAR_SEDAN_DIESEL',
commute_distance: 50
},
{
commute_method: 'CAR_SUV_ELECTRIC',
commute_distance: 50
},
{
commute_method: 'CAR_SUV_CNG',
commute_distance: 50
},
{
commute_method: 'CAR_SUV_PETROL',
commute_distance: 50
},
{
commute_method: 'CAR_SUV_DIESEL',
commute_distance: 50
}
]
}
});
const options = {
method: 'POST',
headers: headers,
body: body
};
fetch(url, options)
.then(response => response.text())
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Error:', error);
});
var axios = require('axios');
var data = JSON.stringify({
"queries": {
"legs": [
{
"commute_method": "TRAIN",
"commute_distance": 50
},
{
"commute_method": "AUTO",
"commute_distance": 50
},
{
"commute_method": "INTRACITY_BUS",
"commute_distance": 50
},
{
"commute_method": "CAB",
"commute_distance": 50
},
{
"commute_method": "BIKE_COMMUTER",
"commute_distance": 50
},
{
"commute_method": "BIKE_SPORTS",
"commute_distance": 50
},
{
"commute_method": "BIKE_CRUISER",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_DIESEL",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_DIESEL",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_DIESEL",
"commute_distance": 50
}
]
}
});
var config = {
method: 'post',
url: 'BASE_URL/v3/commute',
headers: {
'x-api-key': 'API_KEY',
'Content-Type': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
import requests
import json
url = "BASE_URL/v3/commute"
payload = json.dumps({
"queries": {
"legs": [
{
"commute_method": "TRAIN",
"commute_distance": 50
},
{
"commute_method": "AUTO",
"commute_distance": 50
},
{
"commute_method": "INTRACITY_BUS",
"commute_distance": 50
},
{
"commute_method": "CAB",
"commute_distance": 50
},
{
"commute_method": "BIKE_COMMUTER",
"commute_distance": 50
},
{
"commute_method": "BIKE_SPORTS",
"commute_distance": 50
},
{
"commute_method": "BIKE_CRUISER",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_DIESEL",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_DIESEL",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_DIESEL",
"commute_distance": 50
}
]
}
})
headers = {
'x-api-key': 'API_KEY',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('BASE_URL/v3/commute');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'x-api-key' => 'API_KEY',
'Content-Type' => 'application/json'
));
$request->setBody('{
"queries": {
"legs": [
{
"commute_method": "TRAIN",
"commute_distance": 50
},
{
"commute_method": "AUTO",
"commute_distance": 50
},
{
"commute_method": "INTRACITY_BUS",
"commute_distance": 50
},
{
"commute_method": "CAB",
"commute_distance": 50
},
{
"commute_method": "BIKE_COMMUTER",
"commute_distance": 50
},
{
"commute_method": "BIKE_SPORTS",
"commute_distance": 50
},
{
"commute_method": "BIKE_CRUISER",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_DIESEL",
"commute_distance": 50
},
{
"commute_method": "CAR_HATCHBACK_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SEDAN_DIESEL",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_ELECTRIC",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_CNG",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_PETROL",
"commute_distance": 50
},
{
"commute_method": "CAR_SUV_DIESEL",
"commute_distance": 50
}
]
}
}');
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
Sample Response
Below are sample responses for the above request.
Responses
- Success - 200
- Failure - 400
- Failure - 500
{
"message": "Truecost calculated successfully",
"truecost": {
"total_truecost": 2.337,
"legs_truecost": {
"TRAIN": 0.123,
"AUTO": 0.123,
"INTRACITY_BUS": 0.123,
"CAB": 0.123,
"BIKE_COMMUTER": 0.123,
"BIKE_SPORTS": 0.123,
"BIKE_CRUISER": 0.123,
"CAR_HATCHBACK_ELECTRIC": 0.123,
"CAR_HATCHBACK_CNG": 0.123,
"CAR_HATCHBACK_DIESEL": 0.123,
"CAR_HATCHBACK_PETROL": 0.123,
"CAR_SEDAN_ELECTRIC": 0.123,
"CAR_SEDAN_CNG": 0.123,
"CAR_SEDAN_PETROL": 0.123,
"CAR_SEDAN_DIESEL": 0.123,
"CAR_SUV_ELECTRIC": 0.123,
"CAR_SUV_CNG": 0.123,
"CAR_SUV_PETROL": 0.123,
"CAR_SUV_DIESEL": 0.123
}
}
}
{
"message": "Bad Request! Please send all the variables properly."
}
{
"message": "Server Error! Failed to get Commute Truecost."
}