track_shipment
Retrieve the current status and complete tracking history of an APC Overnight parcel using its waybill number.
Instructions
Get the current status and tracking history for an APC Overnight consignment.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| waybill | Yes | The 22-digit WayBill number |
Implementation Reference
- src/carriers/apc.js:392-406 (handler)The core handler function `trackConsignment` that calls APC API endpoint /Tracks/{waybill}.json with searchtype=CarrierWaybill&history=yes and returns status, events, and raw tracking data.
export async function trackConsignment(waybill) { const path = `/Tracks/${waybill}.json?searchtype=CarrierWaybill&history=yes`; const result = await request('GET', path); const tracks = result?.Tracks; const track = Array.isArray(tracks?.Track) ? tracks.Track[0] : tracks?.Track; return { success: true, waybill, status: track?.Status || track?.Description || 'Unknown', events: Array.isArray(tracks?.Track) ? tracks.Track : (track ? [track] : []), raw: result, }; } - src/index.js:267-269 (schema)Input schema: requires a single 'waybill' parameter (22-digit string).
{ waybill: z.string().describe('The 22-digit WayBill number'), }, - src/index.js:264-291 (registration)Tool registration via server.tool('track_shipment', ...) with description and handler that calls apc.trackConsignment.
server.tool( 'track_shipment', 'Get the current status and tracking history for an APC Overnight consignment.', { waybill: z.string().describe('The 22-digit WayBill number'), }, async ({ waybill }) => { try { const result = await apc.trackConsignment(waybill); return { content: [{ type: 'text', text: JSON.stringify({ success: result.success, waybill, status: result.status, events: result.events, }, null, 2), }], }; } catch (err) { return { content: [{ type: 'text', text: `Error tracking shipment: ${err.message}` }], isError: true, }; } } ); - src/carriers/apc.js:198-222 (helper)The `request` helper function used by trackConsignment to make authenticated HTTP requests to the APC API.
async function request(method, path, body = null) { const url = `${BASE_URL}${path}`; const options = { method, headers: { 'remote-user': getAuthHeader(), 'Content-Type': 'application/json', 'Accept': 'application/json', }, }; if (body) { options.body = JSON.stringify(body); } const response = await fetch(url, options); if (!response.ok) { const error = await response.text(); throw new Error(`APC API ${response.status}: ${error}`); } return response.json(); }