Validation Errors
Validation Errors
Section titled “Validation Errors”BigshipValidationError
Section titled “BigshipValidationError”The SDK validates requests client-side before sending. A BigshipValidationError includes field-level error details:
import { BigshipValidationError } from "@agamya/bigship-sdk";
try { await client.createOrder(orderPayload);} catch (err) { if (err instanceof BigshipValidationError) { console.error("Validation failed:"); for (const [field, messages] of Object.entries(err.validationErrors)) { console.error(` ${field}: ${messages.join(", ")}`); } }}Missing Required Fields
Section titled “Missing Required Fields”B2B shipments require invoice_document_file and ewaybill_number. Omitting either triggers a validation error:
// ❌ Missing fields for B2Bawait client.createOrder({ segment_type: "domestic_b2b", // invoice_document_file: "...", // required for B2B // ewaybill_number: "...", // required for B2B // ...other fields});Ensure required fields are present for B2B orders.
Invalid Pincode Format
Section titled “Invalid Pincode Format”Pincodes must be exactly 6 digits:
// ❌ Invalidpincode: "11001" // 5 digitspincode: "11001A" // contains letter
// ✅ Validpincode: "110001"Duplicate Invoice ID → BigshipDuplicateInvoiceError
Section titled “Duplicate Invoice ID → BigshipDuplicateInvoiceError”Reusing an invoice_id within the same account triggers BigshipDuplicateInvoiceError:
import { BigshipDuplicateInvoiceError } from "@agamya/bigship-sdk";
try { await client.createOrder(orderPayload);} catch (err) { if (err instanceof BigshipDuplicateInvoiceError) { console.error("Duplicate invoice:", err.message); // Use a unique invoice_id }}Generate unique invoice IDs (e.g., using uuid or a timestamp-based scheme).
B2C totalNumOfBoxes Must Be 1
Section titled “B2C totalNumOfBoxes Must Be 1”For B2C orders, totalNumOfBoxes is restricted to 1:
// ❌ Invalid for B2Cawait client.createOrder({ segment_type: "domestic_b2c", totalNumOfBoxes: 3, // ...});
// ✅ Valid for B2Cawait client.createOrder({ segment_type: "domestic_b2c", totalNumOfBoxes: 1, // ...});Prepaid Orders: collectableAmount Must Be 0
Section titled “Prepaid Orders: collectableAmount Must Be 0”For prepaid orders, collectableAmount must be 0:
// ❌ Invalid for prepaidawait client.createOrder({ segment_type: "domestic_b2c", MasterOrderPaymentMode: 1, // Prepaid boxes: [{ products: [{ collectableAmount: 500, // ... }], }],});
// ✅ Valid for prepaidawait client.createOrder({ segment_type: "domestic_b2c", MasterOrderPaymentMode: 1, // Prepaid boxes: [{ products: [{ collectableAmount: 0, // ... }], }],});For COD orders, set collectableAmount to the amount to collect from the customer.