Container | Custom Tare Weight | Rail | Climes API
Logistics Freights API's are useful to calculate the truecost value of a single shipment having multiple factors.
Request Parameters
Endpoint
/v3/logistics/freight
Method
POST;
Headers
{
'x-api-key': 'API_KEY',
'Content-Type': 'application/json'
}
Payload
{
"configs": {
"region": "IN",
"transportation_type": "rail"
},
"queries": {
"legs": [{
"shipping_method": "container",
"weight": 19000,
"distance": 18000,
"container_type": "45GP",
"container_tare_weight": 1600
}]
}
}
Response Parameters
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": 3523,
"legs": [
3523
],
"equivalents": {
"trash_collected": "149728",
"trees_planted": "58130",
"lamps_collected": "133522"
}
}
}
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 :::
Sample Request
- cURL
- NodeJs
- Axios
- Python
- Php
curl --location --request POST 'BASE_URL/logistics/freight'
--header 'x-api-key: API_KEY'
--header 'Content-Type: application/json'
--data-raw '{
"configs": {
"region": "IN",
"transportation_type": "rail"
},
"queries": {
"legs": [{
"shipping_method": "container",
"weight": 19000,
"distance": 18000,
"container_type": "45GP",
"container_tare_weight": 1600
}]
}
}
'
const fetch = require('node-fetch');
const url = 'BASE_URL/logistics/freight';
const apiKey = 'API_KEY';
const headers = {
'x-api-key': apiKey,
'Content-Type': 'application/json'
};
const body = JSON.stringify({
configs: {
region: 'IN',
transportation_type: 'rail'
},
queries: {
legs: [
{
shipping_method: 'container',
weight: 19000,
distance: 18000,
container_type: '45GP',
container_tare_weight: 1600
}
]
}
});
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": {
"region": "IN",
"transportation_type": "rail"
},
"queries": {
"legs": [
{
"shipping_method": "container",
"weight": 19000,
"distance": 18000,
"container_type": "45GP",
"container_tare_weight": 1600
}
]
}
});
var config = {
method: 'post',
url: 'BASE_URL/logistics/freight',
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/logistics/freight"
payload = json.dumps({
"configs": {
"region": "IN",
"transportation_type": "rail"
},
"queries": {
"legs": [
{
"shipping_method": "container",
"weight": 19000,
"distance": 18000,
"container_type": "45GP",
"container_tare_weight": 1600
}
]
}
})
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/logistics/freight');
$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": {
"region": "IN",
"transportation_type": "rail"
},
"queries": {
"legs": [{
"shipping_method": "container",
"weight": 19000,
"distance": 18000,
"container_type": "45GP",
"container_tare_weight": 1600
}]
}
}
');
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": 3523,
"legs": [
3523
],
"equivalents": {
"trash_collected": "149728",
"trees_planted": "58130",
"lamps_collected": "133522"
}
}
}
{
"message": "Bad Request! Please send all the variables properly."
}
{
"message": "Server Error! Failed to get Logistics Truecost."
}