Delhivery shipments can be tracked using Delhivery REST API. Here is how you use the Delhivery REST API.
function devnodes_delhivery_track_order($awb = 0)
{
if (!$awb) {
return false;
}
//you need to get the Authorization token from the Delhivery
$auth_token = "XXXXXXXXXXXXXXXXXX";
$base_url = "https://track.delhivery.com/";
$endpoint = $base_url . 'api/v1/packages/json/';
$url = $endpoint . '?token=' . $auth_token . '&waybill=' . $awb . '&verbose=2';
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $auth_token,
),
);
//we will use wordpress wp_remote_get() to get the REST response
$res = wp_remote_get($url, $args);
$json_data = wp_remote_retrieve_body($res);
$output = json_decode($json_data, true);
$status = [];
if (array_key_exists("ShipmentData", $output)) {
$status["AWB"] = $awb;
$status["Status"] = $output["ShipmentData"][0]["Shipment"]["Status"]["Status"];
$status["PickedupDate"] = $output["ShipmentData"][0]["Shipment"]["PickedupDate"];
$status["DeliveryDate"] = $output["ShipmentData"][0]["Shipment"]["DeliveryDate"];
$status["Destination"] = $output["ShipmentData"][0]["Shipment"]["Destination"];
}
return (!empty($status)) ? $status : false;
}
Here is the typical dump of $json_data.
{
"ShipmentData": [
{
"Shipment": {
"PickUpDate": "2023-02-06T14:35:08",
"Destination": "Imphal East",
"DestRecieveDate": "2023-02-15T09:29:54.845000",
"Scans": [
{
"ScanDetail": {
"ScanDateTime": "2023-02-05T23:15:12.713000",
"ScanType": "UD",
"Scan": "Manifested",
"StatusDateTime": "2023-02-05T23:15:12.713000",
"ScannedLocation": "Chennai_Guindy_C (Tamil Nadu)",
"Instructions": "Shipment details manifested",
"StatusCode": "X-UCI"
}
},
{
"ScanDetail": {
"ScanDateTime": "2023-02-05T23:16:58",
"ScanType": "UD",
"Scan": "Manifested",
"StatusDateTime": "2023-02-05T23:16:58",
"ScannedLocation": "Chennai_Guindy_C (Tamil Nadu)",
"Instructions": "Pickup scheduled",
"StatusCode": "FMPUR-101"
}
},
{
"ScanDetail": {
"ScanDateTime": "2023-02-15T09:29:54.853000",
"ScanType": "UD",
"Scan": "Pending",
"StatusDateTime": "2023-02-15T09:29:54.853000",
"ScannedLocation": "Imphal_MnprUnvrsty_D (Manipur)",
"Instructions": "Shipment Received at Facility",
"StatusCode": "X-IBD3F"
}
},
{
"ScanDetail": {
"ScanDateTime": "2023-02-15T10:30:30.934000",
"ScanType": "UD",
"Scan": "Dispatched",
"StatusDateTime": "2023-02-15T10:30:30.934000",
"ScannedLocation": "Imphal_MnprUnvrsty_D (Manipur)",
"Instructions": "Out for delivery",
"StatusCode": "X-DDD3FD"
}
},
{
"ScanDetail": {
"ScanDateTime": "2023-02-15T11:48:58.002000",
"ScanType": "UD",
"Scan": "Dispatched",
"call_duration": 62,
"StatusDateTime": "2023-02-15T11:48:58.002000",
"geo_location": {
"lat": 20.00000000,
"long": 90.00000000
},
"ScannedLocation": "Imphal_MnprUnvrsty_D (Manipur)",
"Instructions": "Call placed to consignee",
"StatusCode": "ST-114"
}
},
{
"ScanDetail": {
"ScanDateTime": "2023-02-15T12:18:25.002000",
"ScanType": "DL",
"Scan": "Delivered",
"call_duration": 62,
"StatusDateTime": "2023-02-15T12:18:25.002000",
"geo_location": {
"lat": 20.00000000,
"long": 90.00000000
},
"ScannedLocation": "Imphal_MnprUnvrsty_D (Manipur)",
"Instructions": "Delivered to consignee",
"StatusCode": "EOD-38"
}
}
],
"Status": {
"Status": "Delivered",
"StatusLocation": "Imphal_MnprUnvrsty_D (Manipur)",
"StatusDateTime": "2023-02-15T12:18:25.002000",
"RecievedBy": "",
"Instructions": "Delivered to consignee",
"StatusType": "DL",
"StatusCode": "EOD-38"
},
"ReturnPromisedDeliveryDate": null,
"Ewaybill": [],
"InvoiceAmount": 99999,
"ChargedWeight": null,
"PickedupDate": "2023-02-06T14:35:08",
"DeliveryDate": "2023-02-15T12:18:25.002000",
"SenderName": "DEVNODES",
"AWB": "XXXXXXXXXXXXXXX",
"DispatchCount": 1,
"OrderType": "Pre-paid",
"ReturnedDate": null,
"ExpectedDeliveryDate": "2023-02-16T23:59:59",
"RTOStartedDate": null,
"Extras": "",
"FirstAttemptDate": "2023-02-15T10:30:30.934000",
"ReverseInTransit": false,
"Quantity": "",
"Origin": "Chennai_Guindy_C (Tamil Nadu)",
"Consignee": {
"City": "Imphal East",
"Name": "XXXXXXXX XXXXXXXXX",
"Country": "India",
"Address2": [],
"Address3": "",
"PinCode": 111111,
"State": "Manipur",
"Telephone2": "",
"Telephone1": "",
"Address1": []
},
"ReferenceNo": "XXXXXXXXXXXXXXXXX",
"OutDestinationDate": "2023-02-06T20:56:54.163000",
"CODAmount": 0,
"PromisedDeliveryDate": "2023-02-14T23:59:59",
"PickupLocation": "DEVNODES",
"OriginRecieveDate": "2023-02-06T20:56:54.097000"
}
}
]
}