Complete FBS shipment lifecycle management and tracking
Create, approve, and manage FBS shipments
PDF documents, acts, and waybills
Generate shipment and container barcodes
Monitor shipment and document status
Digital waybill formation and retrieval
Initialize new FBS shipment with delivery method and time window
Confirm carriage to change status to "Formed" and enable document generation
Confirm shipment and initiate formation of transport waybill and barcode
Check document formation status until all documents are ready
Retrieve PDF documents, transport waybills, and barcode images
// Complete FBS Shipment Workflow
async function completeFbsShipmentWorkflow() {
try {
// Step 1: Create carriage
const carriage = await deliveryFbsApi.createCarriage({
delivery_method_id: 123,
first_mile_from_time: '09:00',
first_mile_to_time: '18:00'
});
const carriageId = carriage.result?.carriage_id;
if (!carriageId) throw new Error('Failed to create carriage');
// Step 2: Approve carriage
const approved = await deliveryFbsApi.approveCarriage({
carriage_id: carriageId
});
if (!approved.result) throw new Error('Failed to approve carriage');
// Step 3: Create act and documents
const act = await deliveryFbsApi.createAct({
carriage_id: carriageId,
posting_number: ['12345-0001-1', '12345-0002-1']
});
if (!act.result) throw new Error('Failed to create act');
// Step 4: Wait for documents to be ready
let status;
do {
await new Promise(resolve => setTimeout(resolve, 5000)); // Wait 5 seconds
status = await deliveryFbsApi.checkActStatus({
carriage_id: carriageId
});
} while (status.documents?.some(doc => doc.status === 'processing'));
// Step 5: Get documents and barcode
const [documents, barcode] = await Promise.all([
deliveryFbsApi.getAct({
carriage_id: carriageId,
doc_type: 'act'
}),
deliveryFbsApi.getBarcode({
carriage_id: carriageId
})
]);
console.log('FBS shipment workflow completed successfully');
return {
carriageId,
actId: act.act_id,
documents: documents.content,
barcode: barcode.barcode
};
} catch (error) {
console.error('FBS shipment workflow failed:', error);
throw error;
}
}
// Create new FBS carriage
const carriage = await deliveryFbsApi.createCarriage({
delivery_method_id: 123,
first_mile_from_time: '09:00',
first_mile_to_time: '18:00'
});
if (carriage.result?.carriage_id) {
console.log(`Carriage created: ${carriage.result.carriage_id}`);
// Approve the carriage
const approved = await deliveryFbsApi.approveCarriage({
carriage_id: carriage.result.carriage_id
});
if (approved.result) {
console.log('Carriage approved successfully');
// Now you can get shipment list and barcode
}
}
// Create act and get documents
const act = await deliveryFbsApi.createAct({
carriage_id: 12345,
posting_number: ['12345-0001-1', '12345-0002-1']
});
// Check document status
const status = await deliveryFbsApi.checkActStatus({
carriage_id: 12345
});
console.log(`Carriage status: ${status.carriage_status}`);
console.log(`Barcode status: ${status.barcode_status}`);
status.documents?.forEach(doc => {
console.log(`${doc.type}: ${doc.status}`);
});
// Get PDF documents when ready
if (status.documents?.every(doc => doc.status === 'ready')) {
const documents = await deliveryFbsApi.getAct({
carriage_id: 12345,
doc_type: 'act'
});
if (documents.content) {
// Save PDF file from base64
const docBuffer = Buffer.from(documents.content, 'base64');
console.log(`Document received: ${documents.filename}`);
}
}
// Get barcode image and text
const [barcode, barcodeText] = await Promise.all([
deliveryFbsApi.getBarcode({ carriage_id: 12345 }),
deliveryFbsApi.getBarcodeText({ carriage_id: 12345 })
]);
if (barcode.barcode) {
// Save barcode image from base64
const barcodeBuffer = Buffer.from(barcode.barcode, 'base64');
console.log(`Barcode image: ${barcode.content_type}`);
}
if (barcodeText.barcode_text) {
console.log(`Barcode text: ${barcodeText.barcode_text}`);
}
Always check for successful results and implement proper error handling for each step of the workflow.
async function robustCarriageOperation(carriageId: number) {
try {
const result = await deliveryFbsApi.approveCarriage({
carriage_id: carriageId
});
if (!result.result) {
throw new Error('Carriage approval failed');
}
return result;
} catch (error) {
if (error.message.includes('not found')) {
console.error(`Carriage ${carriageId} not found`);
} else if (error.message.includes('already approved')) {
console.warn(`Carriage ${carriageId} already approved`);
}
throw error;
}
}
Use intelligent polling with exponential backoff to monitor document formation status.
async function waitForDocumentReady(carriageId: number, maxAttempts = 30) {
let attempts = 0;
while (attempts < maxAttempts) {
const status = await deliveryFbsApi.checkActStatus({
carriage_id: carriageId
});
const allReady = status.documents?.every(doc =>
doc.status === 'ready' || doc.status === 'error'
);
if (allReady) {
return status;
}
attempts++;
await new Promise(resolve => setTimeout(resolve, 10000)); // Wait 10 seconds
}
throw new Error(`Documents not ready after ${maxAttempts} attempts`);
}
Use batch operations with rate limiting for processing multiple carriages efficiently.
class DeliveryFbsManager {
private readonly batchSize = 10;
async processBatchOperations(carriageIds: number[]) {
const batches = [];
for (let i = 0; i < carriageIds.length; i += this.batchSize) {
batches.push(carriageIds.slice(i, i + this.batchSize));
}
const results = [];
for (const batch of batches) {
const batchResults = await Promise.allSettled(
batch.map(id => this.processCarriage(id))
);
results.push(...batchResults);
// Rate limiting - wait between batches
await new Promise(resolve => setTimeout(resolve, 1000));
}
return results;
}
}
Method | Endpoint | Description |
---|---|---|
π Carriage Management | ||
POST createCarriage | /v1/carriage/create | Create new FBS shipment |
POST approveCarriage | /v1/carriage/approve | Approve created shipment |
POST cancelCarriage | /v1/carriage/cancel | Cancel existing shipment |
POST getCarriage | /v1/carriage/get | Get carriage information |
POST getCarriageDeliveryList | /v1/carriage/delivery/list | List delivery methods and carriages |
POST setPostings | /v1/carriage/set-postings | Modify carriage composition |
POST getCarriageAvailableList | /v1/posting/carriage-available/list | Get available carriages |
π Documents & Acts | ||
POST createAct | /v2/posting/fbs/act/create | Create documents |
POST checkActStatus | /v2/posting/fbs/act/check-status | Check document status |
POST getAct | /v2/posting/fbs/act/get-pdf | Get PDF documents |
POST getActPostings | /v2/posting/fbs/act/get-postings | Get postings in act |
POST getActList | /v2/posting/fbs/act/list | Get acts list |
POST checkDigitalActStatus | /v2/posting/fbs/digital/act/check-status | Check waybill status |
POST getDigitalAct | /v2/posting/fbs/digital/act/get-pdf | Get digital waybill |
π Barcodes & Labels | ||
POST getBarcode | /v2/posting/fbs/act/get-barcode | Get barcode image |
POST getBarcodeText | /v2/posting/fbs/act/get-barcode/text | Get barcode text |
POST getContainerLabels | /v2/posting/fbs/act/get-container-labels | Get container labels |
π§ Utilities | ||
POST splitPosting | /v1/posting/fbs/split | Split posting |