Skip to content

Orders

The SDK provides two methods for creating orders depending on the shipment category.

import {
BigshipClient,
isSuccessResponse,
isFailedResponse,
} from '@agamya/bigship-sdk';

Use createOrder({ segment_type: 'domestic_b2c' }) for Business to Consumer shipments. B2C orders must have totalNumOfBoxes: 1.

const order = await client.createOrder({
segment_type: 'domestic_b2c',
MasterOrderPickUpLocation: 123456,
MasterOrderReturnLocation: 123456,
MasterOrderDate: new Date().toISOString().replace('T', ' ').substring(0, 19),
MasterOrderPaymentMode: 1,
OrderInvoiceNo: `INV-${Date.now()}`,
MasterOrderInvoiceAmount: 2500,
MasterOrderShippingName: 'Rahul Sharma',
MasterOrderShippingMobileNo: '9876543210',
MasterOrderShippingEmail: 'rahul@example.com',
MasterOrderShippingAddress: '42 MG Road Koramangala',
MasterOrderShippingZipCode: '560034',
MasterOrderShippingCity: 'BANGALORE',
MasterOrderShippingState: 'KARNATAKA',
MasterOrderShippingCountry: 'India',
totalNumOfBoxes: 1,
boxes: [{
weight_unit: 'kg',
dimension_unit: 'cm',
noOfBoxes: 1,
dimensions: [{
length: 20,
breadth: 15,
height: 10,
weight: 0.5,
}],
products: [{
productName: 'Wireless Earbuds',
hsn: '85182900', // Optional HSN code
qty: '1',
amount: '2500',
totalAmount: 2500,
collectableAmount: 0,
categoryId: '4', // Electronics
}],
}],
invoice_document_file: 'data:application/pdf;base64,JVBERi0xLjQKJ...',
});

Use createOrder({ segment_type: 'domestic_b2b' }) for Business to Business shipments. B2B orders require ewaybill_number and ewaybill_document_file, and can have multiple boxes.

const order = await client.createOrder({
segment_type: 'domestic_b2b',
MasterOrderPickUpLocation: 123456,
MasterOrderReturnLocation: 123456,
MasterOrderDate: new Date().toISOString().replace('T', ' ').substring(0, 19),
MasterOrderPaymentMode: 1,
OrderInvoiceNo: `B2B-${Date.now()}`,
MasterOrderInvoiceAmount: 50000,
MasterOrderShippingName: 'Priya Patel',
MasterOrderShippingMobileNo: '9123456789',
MasterOrderShippingEmail: 'priya@techcorp.com',
MasterOrderShippingAddress: 'Tower B 5th Floor DLF Cyber City',
MasterOrderShippingZipCode: '122002',
MasterOrderShippingCity: 'DELHI',
MasterOrderShippingState: 'DELHI',
MasterOrderShippingCountry: 'India',
totalNumOfBoxes: 2,
ewaybill_number: '281012345678',
ewaybill_document_file: 'data:application/pdf;base64,JVBERi0xLjQKJ...',
boxes: [{
weight_unit: 'kg',
dimension_unit: 'cm',
noOfBoxes: 1,
dimensions: [{ length: 40, breadth: 30, height: 25, weight: 5 }],
products: [{
productName: 'Server Motherboard',
qty: '1',
amount: '25000',
totalAmount: 25000,
collectableAmount: 0,
categoryId: '4',
}],
}, {
weight_unit: 'kg',
dimension_unit: 'cm',
noOfBoxes: 1,
dimensions: [{ length: 30, breadth: 20, height: 15, weight: 3 }],
products: [{
productName: 'Network Switch',
qty: '2',
amount: '12500',
totalAmount: 25000,
collectableAmount: 0,
categoryId: '4',
}],
}],
invoice_document_file: 'data:application/pdf;base64,JVBERi0xLjQKJ...',
});

Both order types require top-level fields:

Field Description
MasterOrderPickUpLocation Pickup location ID
MasterOrderReturnLocation Return location ID
MasterOrderShippingName Recipient name
MasterOrderShippingMobileNo Recipient phone
MasterOrderShippingAddress Recipient address
MasterOrderShippingZipCode Recipient pincode
MasterOrderShippingCity Recipient city
MasterOrderShippingState Recipient state
MasterOrderShippingCountry Recipient country
boxes Box dimensions and products
invoice_document_file Base64 invoice Data URI

The invoice_id field must be unique across all orders. Duplicate invoice IDs will result in a BigshipDuplicateInvoiceError (HTTP 409).

// Good: unique per order
invoice_id: `INV-${Date.now()}`
// Bad: hardcoded — will fail on second order
invoice_id: 'INV-001'
Type MasterOrderPaymentMode collectableAmount (per product)
Prepaid 1 0
COD 2 Amount to collect
const order = await client.createOrder({
segment_type: 'domestic_b2c',
MasterOrderPickUpLocation: 123456,
MasterOrderReturnLocation: 123456,
MasterOrderDate: new Date().toISOString().replace('T', ' ').substring(0, 19),
MasterOrderPaymentMode: 2, // COD
OrderInvoiceNo: `INV-${Date.now()}`,
MasterOrderInvoiceAmount: 2500,
MasterOrderShippingName: 'Rahul Sharma',
MasterOrderShippingMobileNo: '9876543210',
MasterOrderShippingAddress: '42 MG Road Koramangala',
MasterOrderShippingZipCode: '560034',
MasterOrderShippingCity: 'BANGALORE',
MasterOrderShippingState: 'KARNATAKA',
MasterOrderShippingCountry: 'India',
totalNumOfBoxes: 1,
boxes: [{
weight_unit: 'kg',
dimension_unit: 'cm',
noOfBoxes: 1,
dimensions: [{ length: 20, breadth: 15, height: 10, weight: 0.5 }],
products: [{
productName: 'Wireless Earbuds',
qty: '1',
amount: '2500',
totalAmount: 2500,
collectableAmount: 2500,
categoryId: '4',
}],
}],
invoice_document_file: 'data:application/pdf;base64,JVBERi0xLjQKJ...',
});