Discover how to integrate Bolt.new AI with ShipBob to streamline order fulfillment and shipping. Follow our easy step-by-step guide for a seamless setup.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Create a new file in your Bolt.new AI project called shipbobIntegration.ts. This file will hold all functions that interact with ShipBob’s API. Since Bolt.new AI doesn’t have a terminal, simply add this new file via the project’s file-creation interface and paste in the following code:
const SHIPBOBAPIKEY = process.env.SHIPBOBAPIKEY || 'YOURSHIPBOBAPIKEYHERE';
const SHIPBOBAPIBASE_URL = 'https://api.shipbob.com'; // Replace with ShipBob’s actual API base URL if different
export async function createShipment(orderData: any): Promise {
const url = ${SHIPBOB_API_BASE_URL}/shipments;
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': Bearer ${SHIPBOB_API_KEY}
},
body: JSON.stringify(orderData)
});
return await response.json();
}
export async function getShipmentStatus(shipmentId: string): Promise {
const url = ${SHIPBOB_API_BASE_URL}/shipments/${shipmentId};
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': Bearer ${SHIPBOB_API_KEY}
}
});
return await response.json();
}
Since you cannot use a terminal in Bolt.new AI, add the ShipBob API key directly in your code or use the project’s secrets management tool if available. For a secure setup, use the project’s configuration interface to set an environment variable named SHIPBOBAPIKEY with your ShipBob API key. If you must hardcode temporarily, replace 'YOURSHIPBOBAPIKEYHERE' with your actual key (note that this is not recommended for production).
Open the main file of your Bolt.new AI project (for example, index.ts or main.ts). At the top of this file, import the ShipBob functions from your new integration file. Then, add code where you want to process orders and create shipments. Insert the following code snippet into your main application file:
import { createShipment, getShipmentStatus } from './shipbobIntegration';
// Example order data to be sent to ShipBob
const newOrder = {
orderId: "12345",
items: [
{ sku: "ABC123", quantity: 2 },
{ sku: "XYZ789", quantity: 1 }
],
shippingAddress: {
name: "John Doe",
addressLine1: "123 Main St",
city: "Anytown",
state: "CA",
zipCode: "12345",
country: "USA"
}
};
async function processOrder() {
try {
const shipment = await createShipment(newOrder);
console.log("Shipment created:", shipment);
// Optionally, fetch the shipment status using the returned shipment id
const status = await getShipmentStatus(shipment.id);
console.log("Shipment status:", status);
} catch (error) {
console.error("Error processing shipment:", error);
}
}
// Trigger the order processing function
processOrder();
Once you have added the integration code to both shipbobIntegration.ts and your main file, use the Bolt.new AI project’s Run feature to execute your code. The console should display the response from the ShipBob API for creating a shipment and, if applicable, its current status.
This code uses the global fetch API available in Node.js 18+ environments. If your Bolt.new AI project environment does not support fetch natively, you might need to include a polyfill. Since there is no terminal, insert the following code at the top of your shipbobIntegration.ts file to import a minimal polyfill:
import('node-fetch').then(module => {
(global as any).fetch = module.default;
});
Ensure that any dependency loading via import statements is supported by your runtime environment in Bolt.new AI.
By following these steps, you have integrated ShipBob into your Bolt.new AI project.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.