Learn to integrate v0 with Freightos in this step-by-step guide. Enhance your shipping management and boost efficiency with our straightforward integration tips.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
freightosClient.ts. This file will contain all the functions needed to communicate with the Freightos API.FreightosClient class to call the Freightos API.
export interface FreightQuoteInput {
origin: string;
destination: string;
cargoDetails: {
weight: number;
dimensions: {
length: number;
width: number;
height: number;
};
};
}
export interface FreightQuoteResponse {
quoteId: string;
price: number;
currency: string;
estimatedDelivery: string;
}
export class FreightosClient {
private apiKey: string;
private baseUrl: string;
constructor(apiKey: string, baseUrl: string) {
this.apiKey = apiKey;
this.baseUrl = baseUrl;
}
async getQuote(input: FreightQuoteInput): Promise {
const response = await fetch(${this.baseUrl}/quotes, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': Bearer ${this.apiKey}
},
body: JSON.stringify({
origin: input.origin,
destination: input.destination,
cargoDetails: input.cargoDetails
})
});
if (!response.ok) {
throw new Error(Error fetching quote: ${response.statusText});
}
return await response.json();
}
}
main.ts or the relevant file in your project).FreightosClient, creates an instance with your API key and base URL, and calls the getQuote method.
// Import the FreightosClient from the file you just created
import { FreightosClient, FreightQuoteInput } from "./freightosClient";
// Replace these with your actual Freightos API key and base URL
const freightosApiKey = "YOURAPIKEY_HERE";
const freightosBaseUrl = "https://api.freightos.com"; // Adjust the URL based on Freightos documentation
// Create an instance of the FreightosClient
const freightosClient = new FreightosClient(freightosApiKey, freightosBaseUrl);
// Function to request a freight quote
async function requestFreightQuote() {
try {
// Define your freight quote input (customize these values as needed)
const input: FreightQuoteInput = {
origin: "NYC",
destination: "LAX",
cargoDetails: {
weight: 200,
dimensions: {
length: 10,
width: 5,
height: 3
}
}
};
// Get the quote from Freightos
const quote = await freightosClient.getQuote(input);
console.log("Freight Quote:", quote);
} catch (error) {
console.error("Error fetching freight quote:", error);
}
}
// Call the function to execute the API request
requestFreightQuote();
npm install commands directly. Instead, ensure that your project environment supports TypeScript and the Fetch API natively.
// Polyfill for fetch if it is not available in your environment
if (typeof fetch !== "function") {
// Minimal fetch polyfill implementation (for example purposes only)
const fetch = require('node-fetch');
}
freightosClient.ts and your main TypeScript file).
FreightQuoteInput parameters based on your project requirements or additional Freightos API specifications.When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.