SUV Commute Truecost | Climes API
This endpoint provides the truecost of commuting in an SUV
Request Parameters
Request Schema
This is the schema for the suv commute truecost api.
Each request payload requires configs
Configs Schema
Name | Description | Type | Optional |
---|---|---|---|
distance | The total distance of the journey in km. Default will be set as 100(km) | number | optional |
vehicle_type | Type of vehicle used for the journey. | string Enum : SUV | required |
total_capacity | Total number of seats in the suv. Default will be set as 8. | number | optional |
seats_occupied | Total number of seats that will be occupied by the user. Default will be set at 7 | number | optional |
Endpoint
/v3/transportation
Method
POST
Headers
{
'x-api-key' : 'API_KEY',
'Content-Type' : 'application/json'
}
Payload
{
"configs": {
"distance": 50,
"vehicle_type": "SUV",
"total_capacity": 8,
"seats_occupied": 6
}
}
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 for the request. | object |
entire_suv_truecost | This is the total truecost in Kg CO2e for the entire suv. | number |
individual_seat_truecost | This is the total truecost in Kg CO2e for the each occupied seat of that suv.This number is obtained by simply dividing entire_suv_truecost with seats_occupied . | number |
caution
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
{
"message" : "Truecost calculated successfully",
"truecost" : {
"entire_suv_truecost" : 24,
"individual_seat_truecost" : 4
}
}
Sample Request
- cURL
- NodeJs
- Axios
- Python
- Php
curl --location --request POST 'BASE_URL/v3/transportation'
--header 'x-api-key: API_KEY'
--header 'Content-Type: application/json'
--data-raw '{
"configs": {
"distance": 50,
"vehicle_type": "SUV",
"total_capacity": 8,
"seats_occupied": 6
}
}'
const fetch = require('node-fetch');
const url = 'BASE_URL/v3/transportation';
const apiKey = 'API_KEY';
const headers = {
'x-api-key': apiKey,
'Content-Type': 'application/json'
};
const body = JSON.stringify({
configs: {
distance: 50,
vehicle_type: 'SUV',
total_capacity: 8,
seats_occupied: 6
}
});
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({
"configs": {
"distance": 50,
"vehicle_type": "SUV",
"total_capacity": 8,
"seats_occupied": 6
}
});
var config = {
method: 'post',
url: 'BASE_URL/v3/transportation',
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/transportation"
payload = json.dumps({
"configs": {
"distance": 50,
"vehicle_type": "SUV",
"total_capacity": 8,
"seats_occupied": 6
}
})
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/transportation');
$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('{
"configs": {
"distance": 50,
"vehicle_type": "SUV",
"total_capacity": 8,
"seats_occupied": 6
}
}');
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": {
"entire_suv_truecost": 24,
"individual_seat_truecost": 4
}
}
{
"message": "Bad Request! Please send all the variables properly."
}
{
"message": "Server Error! Failed to get Transportation Truecost."
}