Logistics Truecost | Climes API
Logistics API's are useful to calculate the truecost value of a single shipment that is being delivered via multi chain delivery process.
Request Parameters
Request Schema
This is the schema for the logistics 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 |
---|---|---|---|
shipping_method | Its the type of vehicle used to send the shipment from Point A to B. Enums : SHIP TRUCK_LIGHT TRUCK_MEDIUM TRUCK_HEAVY FLIGHT TRAIN MOTORCYCLE | string | required |
shipping_distance | Its the total distance in km that the shipment will travel for that particular shipping_method . Default is set as 100 km. | number | optional |
shipping_weight | Its the total weight of the shipment in ton that has to be sent via this shipping_method . Default is set as 20 tonnes. | number | optional |
truck_capacity | Its only applicable to shipping_method which are one of the following : TRUCK_LIGHT , TRUCK_MEDIUM , TRUCK_HEAVY . Its the maximum load bearing capacity of truck in tonnes.Default values for truck_capacity of types are as below : TRUCK_LIGHT : 1.75 tonnes TRUCK_MEDIUM : 7.75 tonnesTRUCK_HEAVY : 15 tonnes | number | optional |
Endpoint
/v3/logistics
Method
POST
Headers
{
'x-api-key': 'API_KEY',
'Content-Type': 'application/json'
}
Payload
{
"queries": {
"legs": [
{
"shipping_method": "SHIP",
"shipping_distance": 546,
"shipping_weight": 52
},
{
"shipping_method": "TRUCK_LIGHT",
"shipping_distance": 324,
"shipping_weight": 52,
"truck_capacity": 7
},
{
"shipping_method": "TRUCK_MEDIUM",
"shipping_distance": 324,
"shipping_weight": 52,
"truck_capacity": 7
},
{
"shipping_method": "TRUCK_HEAVY",
"shipping_distance": 43534,
"shipping_weight": 52,
"truck_capacity": 15
},
{
"shipping_method": "FLIGHT",
"shipping_distance": 2342,
"shipping_weight": 52
},
{
"shipping_method": "TRAIN",
"shipping_distance": 324,
"shipping_weight": 52
},
{
"shipping_method": "MOTORCYCLE",
"shipping_distance": 23,
"shipping_weight": 52
}
]
}
}
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 object contains the calculated truecost values in tonnes CO2e for the request. | number |
legs | Contains the truecost values in tonnes CO2e of each shipping_method in the exact order of the request's legs. | array |
equivalents | This object contains the equivalents for the calculated truecost values of legs in request. | object |
trash_collected | Its the total number of trash bags collected for recycle for the response's total_truecost | string |
trees_planted | Its the total number of seedlings planted and grown for 10 years for the amount of response's total_truecost | string |
lamps_collected | Its the total lamps' electricity saved for the response's total_truecost | 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
The response will contain the truecost values in tonnes CO2e for each shipping_method as per the request order respectively.
{
"message": "Truecost calculated successfully",
"truecost": {
"total_truecost": 306.933,
"legs": [
0.458,
0.739,
1.427,
111.302,
192.804,
0.16,
0.043
],
"equivalents": {
"trash_collected": "13045",
"trees_planted": "5064",
"lamps_collected": "11633"
}
}
}
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/logistics'
--header 'x-api-key: API_KEY'
--header 'Content-Type: application/json'
--data-raw '{
"queries": {
"legs": [
{
"shipping_method": "SHIP",
"shipping_distance": 546,
"shipping_weight": 52
},
{
"shipping_method": "TRUCK_LIGHT",
"shipping_distance": 324,
"shipping_weight": 52,
"truck_capacity": 7
},
{
"shipping_method": "TRUCK_MEDIUM",
"shipping_distance": 324,
"shipping_weight": 52,
"truck_capacity": 7
},
{
"shipping_method": "TRUCK_HEAVY",
"shipping_distance": 43534,
"shipping_weight": 52,
"truck_capacity": 15
},
{
"shipping_method": "FLIGHT",
"shipping_distance": 2342,
"shipping_weight": 52
},
{
"shipping_method": "TRAIN",
"shipping_distance": 324,
"shipping_weight": 52
},
{
"shipping_method": "MOTORCYCLE",
"shipping_distance": 23,
"shipping_weight": 52
}
]
}
}
'
const fetch = require('node-fetch');
const url = 'BASE_URL/v3/logistics';
const apiKey = 'API_KEY';
const headers = {
'x-api-key': apiKey,
'Content-Type': 'application/json'
};
const body = JSON.stringify({
queries: {
legs: [
{
shipping_method: 'SHIP',
shipping_distance: 546,
shipping_weight: 52
},
{
shipping_method: 'TRUCK_LIGHT',
shipping_distance: 324,
shipping_weight: 52,
truck_capacity: 7
},
{
shipping_method: 'TRUCK_MEDIUM',
shipping_distance: 324,
shipping_weight: 52,
truck_capacity: 7
},
{
shipping_method: 'TRUCK_HEAVY',
shipping_distance: 43534,
shipping_weight: 52,
truck_capacity: 15
},
{
shipping_method: 'FLIGHT',
shipping_distance: 2342,
shipping_weight: 52
},
{
shipping_method: 'TRAIN',
shipping_distance: 324,
shipping_weight: 52
},
{
shipping_method: 'MOTORCYCLE',
shipping_distance: 23,
shipping_weight: 52
}
]
}
});
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": [
{
"shipping_method": "SHIP",
"shipping_distance": 546,
"shipping_weight": 52
},
{
"shipping_method": "TRUCK_LIGHT",
"shipping_distance": 324,
"shipping_weight": 52,
"truck_capacity": 7
},
{
"shipping_method": "TRUCK_MEDIUM",
"shipping_distance": 324,
"shipping_weight": 52,
"truck_capacity": 7
},
{
"shipping_method": "TRUCK_HEAVY",
"shipping_distance": 43534,
"shipping_weight": 52,
"truck_capacity": 15
},
{
"shipping_method": "FLIGHT",
"shipping_distance": 2342,
"shipping_weight": 52
},
{
"shipping_method": "TRAIN",
"shipping_distance": 324,
"shipping_weight": 52
},
{
"shipping_method": "MOTORCYCLE",
"shipping_distance": 23,
"shipping_weight": 52
}
]
}
});
var config = {
method: 'post',
url: 'BASE_URL/v3/logistics',
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/logistics"
payload = json.dumps({
"queries": {
"legs": [
{
"shipping_method": "SHIP",
"shipping_distance": 546,
"shipping_weight": 52
},
{
"shipping_method": "TRUCK_LIGHT",
"shipping_distance": 324,
"shipping_weight": 52,
"truck_capacity": 7
},
{
"shipping_method": "TRUCK_MEDIUM",
"shipping_distance": 324,
"shipping_weight": 52,
"truck_capacity": 7
},
{
"shipping_method": "TRUCK_HEAVY",
"shipping_distance": 43534,
"shipping_weight": 52,
"truck_capacity": 15
},
{
"shipping_method": "FLIGHT",
"shipping_distance": 2342,
"shipping_weight": 52
},
{
"shipping_method": "TRAIN",
"shipping_distance": 324,
"shipping_weight": 52
},
{
"shipping_method": "MOTORCYCLE",
"shipping_distance": 23,
"shipping_weight": 52
}
]
}
})
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/logistics');
$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": [
{
"shipping_method": "SHIP",
"shipping_distance": 546,
"shipping_weight": 52
},
{
"shipping_method": "TRUCK_LIGHT",
"shipping_distance": 324,
"shipping_weight": 52,
"truck_capacity": 7
},
{
"shipping_method": "TRUCK_MEDIUM",
"shipping_distance": 324,
"shipping_weight": 52,
"truck_capacity": 7
},
{
"shipping_method": "TRUCK_HEAVY",
"shipping_distance": 43534,
"shipping_weight": 52,
"truck_capacity": 15
},
{
"shipping_method": "FLIGHT",
"shipping_distance": 2342,
"shipping_weight": 52
},
{
"shipping_method": "TRAIN",
"shipping_distance": 324,
"shipping_weight": 52
},
{
"shipping_method": "MOTORCYCLE",
"shipping_distance": 23,
"shipping_weight": 52
}
]
}
}
');
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": 306.933,
"legs": [
0.458,
0.739,
1.427,
111.302,
192.804,
0.16,
0.043
],
"equivalents": {
"trash_collected": "13045",
"trees_planted": "5064",
"lamps_collected": "11633"
}
}
}
{
"message": "Bad Request! Please send all the variables properly."
}
{
"message": "Server Error! Failed to get Logistics Truecost."
}