You can get real-time shipment status information through this API without creating a tracking command. Real-time shipment tracking API will get the shipment information from the carrier and respond, the tracking details after you submit the tracking number. The information includes shipment route, shipment status, date, and time, etc.
Reminder: If you need to obtain massive tracking information and update the information regularly, please use the Create Tracking API and set up a webhook for receiving updates.
POST
https://www.kd100.com/api/v1/tracking/realtime
Key | Value |
Content-Type | application/json |
API-Key | Your API-Key, find on API management |
signature |
How to generate a signature? Use the JSON format of body parameters, concatenate them in the order of Body+API-Key+Secret, and then perform MD5 encryption, converting the encrypted results into string and uppercase. Example: DC0491A58035AB355061F54CB57161E5 |
Content-Type: application/json
API-Key: Enter your API Key here
signature: MD5(Body+API-Key+Secret)
Name | Data Type | Required | Note |
---|---|---|---|
carrier_id | string | true | carrier ID |
tracking_number | string | true | tracking number |
phone | string | false | sender & recipient phone number (fill in with a mobile phone number or landline number) |
ship_from | string | false | sender city |
ship_to | string | false | recipient city. The tracking frequency will be increased when the shipment arrives at the recipient city. |
area_show | number | false | Adding this field means using the administrative area determination feature. 0: close (default) 1: the responses of items return data about order_status_code,order_status_description,location, area_name. |
order | string | false | false Returned data sort: desc(default), asc. |
{
"carrier_id": "dhl",
"tracking_number": "9926933413",
"phone": "95279527",
"ship_from": "Toronto, Canada",
"ship_to": "Los Angeles, CA, United States",
"area_show": 1,
"order": "desc"
}
Name | Data Type | Required | Note |
---|---|---|---|
code | number | false | code 200 means "ok." |
message | string | false | event text |
--data | object | false | |
carrier_id | string | true | carrier ID |
tracking_number | string | true | tracking number |
order_status_code | number | true | the latest shipment status |
--items | object [] | false | |
context | string | true | shipment route description |
time | string | true | shipment route timestamp |
order_status_description | string | false | shipment status description. You need to set the parameter (area_show) value to "1" to use this feature. |
order_status_code | string | false | shipment status code. You need to set the parameter (area_show) value to "1" to use this feature. |
location | string | false | shipment route location information. You need to set the parameter (area_show) value to ,"1," to use this feature. |
area_name | string | false | shipment route area information. You need to set the parameter (area_show) value to ,"1," to use this feature. |
{
"code": 200,
"message": "OK",
"data": {
"carrier_id": "dhl",
"tracking_number": "9926933413",
"order_status_code": 4,
"items": [
{
"context": "Partial delivery",
"time": "2021-07-09 18:47:17",
"order_status_description": "Delivered",
"area_name": "null",
"location": "null"
},
{
"context": "With delivery courier",
"time": "2021-07-09 18:47:02",
"order_status_description": "Out for delivery",
"area_name": "null",
"location": "null"
},
{
"context": "Arrived at Delivery Facility",
"time": "2021-07-08 19:13:10",
"order_status_description": "In transit",
"area_name": "null",
"location": "null"
},
{
"context": "Shipment picked up",
"time": "2021-05-25 04:57:39",
"order_status_description": "Accepted",
"area_name": null,
"location": null
}
]
}
}
{
"code": 60101,
"message": "No result found"
}
# coding = utf-8
import hashlib
import json
import requests
class KuaiDi100:
def __init__(self):
self.API_Key = '' # You can find your API Key on https://app.kd100.com/api-managment
self.Secret = '' # You can find your Secret on https://app.kd100.com/api-managment
self.url = 'https://www.kd100.com/api/v1/tracking/realtime'
def track(self, com, num, phone, ship_from, ship_to):
"""
Request Parameters
:param carrier_id: carrier ID, you can it on https://app.kd100.com/api-management
:param tracking_number: tracking number
:param phone: sender & recipient phone number (fill in with a mobile phone number or landline number)
:param ship_from: sender city
:param ship_to: recipient city. The tracking frequency will be increased when the shipment arrives at the recipient city.
:param area_show: Adding this field means using the administrative area determination feature. 0: close (default) 1: return data about area_name, location, order_status_description
:param order: Returned data sort--desc(default):Descending order, asc:Ascending order.
:return: requests.Response.text
"""
param = {
'carrier_id': com,
'tracking_number': num,
'phone': phone,
'ship_from': ship_from,
'ship_to': ship_to,
'area_show': 1,
'order': 'desc'
}
param_str = json.dumps(param)
temp_sign = param_str + self.API_Key + self.Secret
md = hashlib.md5()
md.update(temp_sign.encode())
sign = md.hexdigest().upper()
headers = {
'API-Key': self.API_Key,
'signature': sign,
'Content-Type': 'application/json'
}
response = requests.request("POST", self.url, headers=headers, data=param_str)
return response.text
result = KuaiDi100().track('dhl', '9926933413', '95279527', 'Toronto, Canada', 'Los Angeles, CA, United States')
print(result)
'dhl', // the carrier code, you can find from https://app.kd100.com/api-management
'tracking_number' => '9926933413', // The tracking number you want to query
'phone' => '', // Phone number
'ship_from' => '', // City of departure
'ship_to' => '', // Destination city
'area_show' => 1, // 0: close (default); 1: return data about area_name, location, order_status_description
'order' => 'desc' // Sorting of returned results: desc - descending (default), asc - ascending
);
// Request Json
$json = json_encode($param, JSON_UNESCAPED_UNICODE);
$signature = strtoupper(md5($json.$key.$secret));
$url = 'https://www.kd100.com/api/v1/tracking/realtime'; // Real-time shipment tracking request address
echo 'request headers key: '.$key;
echo '
request headers signature: '.$signature;
echo '
request json: '.$json;
$headers = array (
'Content-Type:application/json',
'API-Key:'.$key,
'signature:'.$signature,
'Content-Length:'.strlen($json)
);
// Send post request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
$data = json_decode($result, true);
echo '
Return data:
';
echo print_r($data);
//echo var_dump($data);
echo '
';
?>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* Real-time Shipment Tracking
*
* @author https://www.kd100.com/
*
*/
public class RealTimeTracking {
private static final String URL = "https://www.kd100.com/api/v1/tracking/realtime";
//You can find your ApiKey on https://app.kd100.com/api-managment
private static final String API_KEY = "";
//You can find your Secret on https://app.kd100.com/api-managment
private static final String SECRET = "";
private static final int CONNECT_TIMEOUT = 1000;
private static final int READ_TIMEOUT = 5000;
public static void main(String[] args) {
String carrier_id = "dhl";
String tracking_number = "9926933413";
String phone = "95279527";
String ship_from = "Toronto, Canada";
String ship_to = "Los Angeles, CA, United States";
RealTimeTracking demo = new RealTimeTracking();
String result = demo.getData(carrier_id, tracking_number, phone, ship_from, ship_to);
System.out.println(result);
}
public String getData(String carrier_id, String tracking_number, String phone, String ship_from, String ship_to) {
String param = "{" +
"\"carrier_id\": \""+carrier_id+"\"," +
"\"tracking_number\": \""+tracking_number+"\"," +
"\"phone\": \""+phone+"\"," +
"\"ship_from\": \""+ship_from+"\"," +
"\"ship_to\": \""+ship_to+"\"," +
"\"area_show\": 1," +
"\"order\": \"desc\"" +
"}";
String signature = MD5Utils.encode(param + API_KEY + SECRET);
return this.post(param,signature);
}
public String post(String param,String signature) {
StringBuffer response = new StringBuffer("");
byte[] data = param.getBytes();
BufferedReader reader = null;
OutputStream out = null;
try {
URL url = new URL(URL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(CONNECT_TIMEOUT);
conn.setReadTimeout(READ_TIMEOUT);
conn.setRequestMethod("POST");
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Content-Length", String.valueOf(data.length));
conn.setRequestProperty("API-Key",API_KEY);
conn.setRequestProperty("signature",signature);
conn.setDoOutput(true);
out = conn.getOutputStream();
out.write(data);
reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line = "";
while ((line = reader.readLine()) != null) {
response.append(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != out){
out.flush();
out.close();
}
if (null != reader) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return response.toString();
}
}
class MD5Utils {
private static MessageDigest mdigest = null;
private static char digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
private static MessageDigest getMdInst() {
if (null == mdigest) {
try {
mdigest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
return mdigest;
}
public static String encode(String s) {
if(null == s) {
return "";
}
try {
byte[] bytes = s.getBytes();
getMdInst().update(bytes);
byte[] md = getMdInst().digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = digits[byte0 >>> 4 & 0xf];
str[k++] = digits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}