Bus Truecost | Climes API
This endpoint provides the truecost value for bus transportation.
Request Parameters
Request Schema
This is the schema for the bus transportation truecost api. Each request payload contains 2 objects
- queries
- configs
Here configs
are the params that will apply to all the queries
objects
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. Enum : BUS | string | required |
Queries Schema
Each queries
object has a seats
array which requires individual seat object.
Name | Description | Type | Optional |
---|---|---|---|
seats | It holds the array of individual type of seats available for that bus. | array | required |
Seat Schema
Name | Description | Type | Optional |
---|---|---|---|
seat_type | It the type of seat selected by the user in the ticket for the journey. Enum : SEATER , SLEEPER | string | required |
no_of_seats | This is the seats booked by the individual user. Default will be set to 12 for SEATER seat_type and 35 for SLEEPER | number | optional |
total_seats | This is the total capacity of seats that the bus has for that particular seat_type. Default will be set as 14 for SEATER and 40 for SLEEPER seat_type | number | optional |
Endpoint
/v3/transportation
Method
POST
Headers
{
'x-api-key' : 'API_KEY',
'Content-Type' : 'application/json'
}
Payload
{
"configs": {
"distance": 250,
"vehicle_type": "BUS"
},
"queries": {
"seats": [
{
"seat_type": "SEATER",
"no_of_seats": 3,
"total_seats": 15
},
{
"seat_type": "SLEEPER",
"no_of_seats": 3,
"total_seats": 40
}
]
}
}
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 |
total | Total truecost value in kg CO2e of all types of seats that were in the request | number |
seats | It is an object with different types of seats and their truecost values as a key value pair. | object |
SEATER | Total truecost value in kg CO2e for the no_of_seats occupied of SEATER type in the bus | number |
SLEEPER | Total truecost value in kg CO2e for the no_of_seats occupied of SLEEPER type in the bus | 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 data calculated successfully!",
"truecost": {
"total": 35,
"seats": {
"SEATER": 15,
"SLEEPER": 20
}
}
}
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": 250,
"vehicle_type": "BUS"
},
"queries": {
"seats": [
{
"seat_type": "SEATER",
"no_of_seats": 3,
"total_seats": 15
},
{
"seat_type": "SLEEPER",
"no_of_seats": 3,
"total_seats": 40
}
]
}
}'
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: 250,
vehicle_type: 'BUS'
},
queries: {
seats: [
{
seat_type: 'SEATER',
no_of_seats: 3,
total_seats: 15
},
{
seat_type: 'SLEEPER',
no_of_seats: 3,
total_seats: 40
}
]
}
});
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": 250,
"vehicle_type": "BUS"
},
"queries": {
"seats": [
{
"seat_type": "SEATER",
"no_of_seats": 3,
"total_seats": 15
},
{
"seat_type": "SLEEPER",
"no_of_seats": 3,
"total_seats": 40
}
]
}
});
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": 250,
"vehicle_type": "BUS"
},
"queries": {
"seats": [
{
"seat_type": "SEATER",
"no_of_seats": 3,
"total_seats": 15
},
{
"seat_type": "SLEEPER",
"no_of_seats": 3,
"total_seats": 40
}
]
}
})
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": 250,
"vehicle_type": "BUS"
},
"queries": {
"seats": [
{
"seat_type": "SEATER",
"no_of_seats": 3,
"total_seats": 15
},
{
"seat_type": "SLEEPER",
"no_of_seats": 3,
"total_seats": 40
}
]
}
}');
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 data calculated successfully!",
"truecost": {
"total": 35,
"seats": {
"SEATER": 15,
"SLEEPER": 20
}
}
}
{
"message": "Bad Request! Please send all the variables properly."
}
{
"message": "Server Error! Failed to get Transportation Truecost."
}