B2C Shipment Lifecycle
This guide walks through the full B2C (Business to Consumer) shipment lifecycle using the Bigship SDK.
Imports
Section titled “Imports”import { BigshipClient, isSuccessResponse, isFailedResponse, ShipmentDataType,} from '@agamya/bigship-sdk';-
Check Wallet Balance
Verify your wallet has sufficient funds before creating shipments.
const balance = await client.getWalletBalance();if (isSuccessResponse(balance)) {console.log('Balance:', balance.data); // → "5000.00"} -
List Available Couriers
Retrieve couriers available for B2C shipments.
const couriers = await client.getCourierList('b2c');if (isSuccessResponse(couriers)) {for (const c of couriers.data) {console.log(`ID: ${c.courier_id} — ${c.courier_name} (${c.courier_type})`);}}// → ID: 5 — Delhivery (Surface)// → ID: 12 — DTDC (Surface) -
Calculate Shipping Rates
Estimate shipping costs before creating an order.
const rates = await client.calculateRate({shipment_category: 'B2C',payment_type: 'Prepaid',pickup_pincode: '110001',destination_pincode: '400001',shipment_invoice_amount: 2500,box_details: [{each_box_dead_weight: 0.5,each_box_length: 20,each_box_width: 15,each_box_height: 10,box_count: 1,}],}); -
Create Order
Create a B2C order with warehouse, consignee, and order details.
const order = await client.addSingleOrder({shipment_category: 'b2c',warehouse_detail: {pickup_location_id: 123456,return_location_id: 123456,},consignee_detail: {first_name: 'Rahul',last_name: 'Sharma',contact_number_primary: '9876543210',consignee_address: {address_line1: '42 MG Road Koramangala',address_line2: 'Near Forum Mall',address_landmark: 'Opposite HDFC Bank',pincode: '560034',},},order_detail: {invoice_date: new Date().toISOString(),invoice_id: `INV-${Date.now()}`,payment_type: 'Prepaid',total_collectable_amount: 0,shipment_invoice_amount: 2500,box_details: [{each_box_dead_weight: 0.5,each_box_length: 20,each_box_width: 15,each_box_height: 10,each_box_invoice_amount: 2500,each_box_collectable_amount: 0,box_count: 1,product_details: [{product_category: 'Electronics',product_name: 'Wireless Earbuds',product_quantity: 1,each_product_invoice_amount: 2500,each_product_collectable_amount: 0,}],}],document_detail: {invoice_document_file: 'data:application/pdf;base64,JVBERi0xLjQKJ...',},},});if (isFailedResponse(order)) {console.error('Failed:', order.message);process.exit(1);}const orderId = order.data!;console.log('Order created:', orderId); -
Manifest (Assign Courier)
Assign a courier to the order.
await client.manifestSingle({system_order_id: orderId,courier_id: 5, // Delhivery Surface}); -
Get AWB Number
Retrieve the AWB (Air Waybill) number after manifestation.
const awbResp = await client.getShipmentData(ShipmentDataType.AWB, orderId);if (isSuccessResponse(awbResp) && awbResp.data && typeof awbResp.data !== 'string') {console.log('AWB:', awbResp.data.master_awb); // "13090318586270"console.log('Courier:', awbResp.data.courier_name); // "Delhivery"} -
Get Shipping Label
Download the shipping label as a base64 Data URI or URL.
const label = await client.getShipmentData(ShipmentDataType.LABEL, orderId);if (isSuccessResponse(label) && typeof label.data === 'string') {console.log('Label:', label.data.substring(0, 40) + '...');} -
Track Shipment
Track the shipment by AWB number.
const tracking = await client.trackShipment('13090318586270', 'awb');if (isSuccessResponse(tracking)) {console.log('Status:', tracking.data);} -
Cancel if Needed
Cancel one or more shipments by AWB number.
await client.cancelShipments(['13090318586270']);
Convenience Method
Section titled “Convenience Method”Use getShipmentDetails to fetch AWB, label, and manifest in a single call:
const details = await client.getShipmentDetails(orderId);console.log(details.awb); // "13090318586270"console.log(details.courierName); // "Delhivery"console.log(details.labelData); // "data:application/pdf;base64,..."console.log(details.manifestData); // "data:application/pdf;base64,..."