Flight Truecost | Climes API
This endpoint provides the truecost value for flights (upto 10 flights per request).
Request Parameters
Request Schema
This is the schema for the flights truecost api. Each request payload requires queries
Queries Schema
Each queries
object has a flights
array which requires individual flight object.
Name Description | Type | Optional | |
---|---|---|---|
flights | It is an array of individual flights whose truecost needs to be calculated. | array | required |
Flight Schema
Name Description | Type | Optional | |
---|---|---|---|
flight_id | This field has to generated and sent from your end. This has to be unique in order to map each flight truecost data to its original request for tally purposes. If this field is not set then an auto generated unique flight_id will be automatically assigned to that request. | unique string | optional |
departure | The destination airport's IATA code where the flight is going. | string | required |
arrival | The arrival airport's IATA code where the flight will arrive at. | string | required |
no_of_tickets | Number of tickets for which the truecost is being calculated. | number | required |
aircraft_model | The aircraft model that is being used for the journey. Default will be set as 320 | string | optional |
flight_class | The class of flight ticket for which the truecost is being calculated. Default will be set as ECONOMY Enums : ECONOMY , PREMIUM_ECONOMY , FIRST , BUSINESS | string | optional |
flight_type | This is an enum denoting the type of the flight. Default will be set as ONE_WAY Enums : ONE_WAY , ROUND_TRIP | string | optional |
Endpoint
/v3/flight
Method
POST
Headers
{
'x-api-key': 'API_KEY',
'Content-Type': 'application/json'
}
Payload
{
"queries": {
"flights": [{
"flight_id": "BWESYZZE6ECOFOMFDH4",
"departure": "BOS",
"arrival": "YYZ",
"aircraft_model": "DH4",
"flight_class": "ECONOMY",
"no_of_tickets": 1,
"flight_type": "ONE_WAY"
},
{
"flight_id": "FWYSYZZE6ECOFOMOME",
"departure": "BOS",
"arrival": "YYZ",
"aircraft_model": "DH4",
"flight_class": "ECONOMY",
"no_of_tickets": 1,
"flight_type": "ONE_WAY"
}
]
}
}
caution
The length of the flights
array should not be more than 10 individual objects per request.
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 |
flight_id | The flight_id that was sent during the request for each object request | string |
truecost | Calculated truecost value in tonnes CO2e for that object of request | string |
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": [{
"flight_id": "BWESYZZE6ECOFOMFDH4",
"truecost": "0.320"
},
{
"flight_id": "FWYSYZZE6ECOFOMOME",
"truecost": "0.320"
}
]
}
tip
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/flight'
--header 'x-api-key: API_KEY'
--header 'Content-Type: application/json'
--data-raw '{
"queries": {
"flights": [{
"flight_id": "BWESYZZE6ECOFOMFDH4",
"departure": "BOS",
"arrival": "YYZ",
"aircraft_model": "DH4",
"flight_class": "ECONOMY",
"no_of_tickets": 1,
"flight_type": "ONE_WAY"
},
{
"flight_id": "FWYSYZZE6ECOFOMOME",
"departure": "BOS",
"arrival": "YYZ",
"aircraft_model": "DH4",
"flight_class": "ECONOMY",
"no_of_tickets": 1,
"flight_type": "ONE_WAY"
}
]
}
}'
const fetch = require('node-fetch');
const url = 'BASE_URL/v3/flight';
const apiKey = 'API_KEY';
const headers = {
'x-api-key': apiKey,
'Content-Type': 'application/json'
};
const body = JSON.stringify({
queries: {
flights: [
{
flight_id: 'BWESYZZE6ECOFOMFDH4',
departure: 'BOS',
arrival: 'YYZ',
aircraft_model: 'DH4',
flight_class: 'ECONOMY',
no_of_tickets: 1,
flight_type: 'ONE_WAY'
},
{
flight_id: 'FWYSYZZE6ECOFOMOME',
departure: 'BOS',
arrival: 'YYZ',
aircraft_model: 'DH4',
flight_class: 'ECONOMY',
no_of_tickets: 1,
flight_type: 'ONE_WAY'
}
]
}
});
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": {
"flights": [
{
"flight_id": "BWESYZZE6ECOFOMFDH4",
"departure": "BOS",
"arrival": "YYZ",
"aircraft_model": "DH4",
"flight_class": "ECONOMY",
"no_of_tickets": 1,
"flight_type": "ONE_WAY"
},
{
"flight_id": "FWYSYZZE6ECOFOMOME",
"departure": "BOS",
"arrival": "YYZ",
"aircraft_model": "DH4",
"flight_class": "ECONOMY",
"no_of_tickets": 1,
"flight_type": "ONE_WAY"
}
]
}
});
var config = {
method: 'post',
url: 'BASE_URL/v3/flight',
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/flight"
payload = json.dumps({
"queries": {
"flights": [
{
"flight_id": "BWESYZZE6ECOFOMFDH4",
"departure": "BOS",
"arrival": "YYZ",
"aircraft_model": "DH4",
"flight_class": "ECONOMY",
"no_of_tickets": 1,
"flight_type": "ONE_WAY"
},
{
"flight_id": "FWYSYZZE6ECOFOMOME",
"departure": "BOS",
"arrival": "YYZ",
"aircraft_model": "DH4",
"flight_class": "ECONOMY",
"no_of_tickets": 1,
"flight_type": "ONE_WAY"
}
]
}
})
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/flight');
$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": {
"flights": [{
"flight_id": "BWESYZZE6ECOFOMFDH4",
"departure": "BOS",
"arrival": "YYZ",
"aircraft_model": "DH4",
"flight_class": "ECONOMY",
"no_of_tickets": 1,
"flight_type": "ONE_WAY"
},
{
"flight_id": "FWYSYZZE6ECOFOMOME",
"departure": "BOS",
"arrival": "YYZ",
"aircraft_model": "DH4",
"flight_class": "ECONOMY",
"no_of_tickets": 1,
"flight_type": "ONE_WAY"
}
]
}
}');
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": [
{
"flight_id": "BWESYZZE6ECOFOMFDH4",
"truecost": "0.320"
},
{
"flight_id": "FWYSYZZE6ECOFOMOME",
"truecost": "0.320"
}
]
}
{
"message": "Bad Request! Please send all the variables properly."
}
{
"message": "Server Error! Failed to get Flight Truecost."
}