Rates
The SDK provides two methods for rate-related operations: pre-shipment rate estimation and post-order rate comparison.
Imports
Section titled “Imports”import { BigshipClient, isSuccessResponse,} from '@agamya/bigship-sdk';Calculate Rates — calculateRate
Section titled “Calculate Rates — calculateRate”Estimate shipping costs before creating an order.
const rates = await client.calculateRate({ segment_type: 'domestic_b2c', sourcePincode: '110001', destPincode: '400001', invoiceValue: 2500, paymentModeId: 1, // 1: Prepaid, 2: COD, 3: ToPay riskTypeId: 2, // 1: Third Party Insurance, 2: Owner Risk, 3: Carrier Risk boxes: [{ box_length: 20, box_width: 15, box_height: 10, box_dead_weight: 0.5, noOfBoxes: 1, }],});
if (isSuccessResponse(rates)) { const cheapest = rates.data.sort((a, b) => a.totalCharge - b.totalCharge)[0]; console.log(`Best rate: ${cheapest.courierName} — ₹${cheapest.totalCharge}`);}Get Serviceable Couriers — getServiceableCouriers
Section titled “Get Serviceable Couriers — getServiceableCouriers”Compare shipping rates for an existing draft order. This is useful when you want to pick the cheapest courier after creating an order.
const couriers = await client.getServiceableCouriers(orderId);if (isSuccessResponse(couriers)) { for (const rate of couriers.data.calculatedRates) { console.log(`${rate.courierName}: ₹${rate.total} (${rate.tat} days)`); }}Get Serviceable Couriers — getServiceableCouriers
Section titled “Get Serviceable Couriers — getServiceableCouriers”Retrieve available couriers and their rates for a draft order.
const couriers = await client.getServiceableCouriers(orderId);if (isSuccessResponse(couriers)) { for (const c of couriers.data.calculatedRates) { console.log(`ID: ${c.courierId} — ${c.courierName} (${c.courierType})`); }}// → ID: 5 — Delhivery (Surface)// → ID: 12 — DTDC (Surface)Pass segment_type: 'domestic_b2b' for B2B couriers:
const b2bCouriers = await client.getServiceableCouriers(b2bOrderId);