Flight Bulk Truecost | Climes API
This endpoint provides the truecost value for flights in bulk (upto 500 flights per request).
This endpoint has 2 parts in its integration.
- Sending the flight data in the below endpoint for processing.
- Get a processed flights result with calculated truecost values sent to the endpoint given by you in below format.
Here firstly you will send the flights data using the below endpoint. This data will be then processed internally and will be sent back to you via the endpoint that you provide in the below format
Request Parameters
Request Schema
This is the schema for the flights bulk truecost api.
Flight Schema
Each request body is an array which requires individual objects with below parameters.
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. | unique string | required |
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. Enums : ECONOMY , PREMIUM_ECONOMY , FIRST , BUSINESS | string | required |
flight_type | This is an enum denoting the type of the flight. Enums : ONE_WAY , ROUND_TRIP | string | required |
Endpoint
/v3/flight/bulk
Method
POST
Headers
{
'x-api-key': 'API_KEY',
'Content-Type': 'application/json'
}
Payload
[
{
"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"
}
]
If you want to calculate and store the flight's truecost value for future use, send the no_of_tickets
as 1 and in future just multiply the value of this flight's truecost by the number of tickets so that you don't have to query this data again
The length of the payload should be less than 500 individual objects per request.
Response Parameters
Response Schema
Name | Description | Type |
---|---|---|
message | A human readable string describing response for the given request. | string |
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": "The flight data has been added successfully!",
}
Sample Request
- cURL
- NodeJs
- Axios
- Python
- Php
curl --location --request POST 'BASE_URL/v3/flight/bulk'
--header 'x-api-key: API_KEY'
--header 'Content-Type: application/json'
--data-raw '[{
"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/bulk';
const apiKey = 'API_KEY';
const headers = {
'x-api-key': apiKey,
'Content-Type': 'application/json'
};
const body = JSON.stringify([
{
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([
{
"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/bulk',
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/bulk"
payload = json.dumps([
{
"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/bulk');
$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('[{
"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": "The flight data has been added successfully!"
}
{
"message": "Bad Request! Please send all the variables properly."
}
{
"message": "Server Error! Failed to get Flight Truecost."
}
Calculated Values Response Format
This the format in which the calculated response will be sent to your configured endpoint.
The response will be in the following format as key value pairs where keys are the flight_id
sent during the request and the values are the truecost values in tonnes CO2e for that individual flight request object.
{
"BWESYZZE6ECOFOMFDH4": "0.123",
"FWYSYZZE6ECOFOMOME": "0.123"
}