Features Pricing Developers Company Blog Login Start for free

Carrier Auto-detection

Introduction

You can submit the courier tracking number through this API to determine the carrier ID to which the tracking number may belong. The returned data is a list of possible carrier IDs, and the carrier ID with high possibility ranks first.

Reminder: The tracking number of each carrier is constantly changing, and there is no standardized rule for tracking number naming. We cannot guarantee that the returned result is 100 percent accurate. Our existing mechanism uses our accumulated data to analyze each carrier’s tracking number naming rule and update the rules daily.

We will not provide legal commitments on the accuracy and validity of the returned result. If you provide this service to your users, it is recommended that you should use the following reminders when giving the tracking result to your users:

  • Add a description such as "Possible Results" or "Possible Results Powered by KeyDelivery" or "This Result Is for Reference Only."
  • The user can manually modify the carrier.

Url

                                    POST
                                    https://www.kd100.com/api/v1/carriers/detect
                                

Headers

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

 

Header

                                    Content-Type: application/json
API-Key: Enter your API Key here
signature: MD5(json+API-Key+Secret)
                                

Body

NameData TypeRequiredNote
tracking_numberstringfalsetracking number

Parameters

                                    {
  "tracking_number": "8247502336" 
}
                                

Responses

NameData TypeRequiredNote
codenumberfalseok
messagestringfalseevent text
dataobject []false
carrier_idstringtruecarrier ID
carrier_namestringtruecarrier name

Response

200
                                    {
  "code": 200,
  "message": "OK",
  "data": [
    {
      "carrier_id": "dhl_de",
      "carrier_name": "DHL Deutschland"
    },
    {
      "carrier_id": "dhl_benelux",
      "carrier_name": "DHL Benelux"
    }
  ]
}
                                

Demo

Response

PythonPHPJAVA
                                    # 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/carriers/detect'

    def track(self, num):
        """
        Request Parameters
        :param tracking_number: tracking number
        :return: requests.Response.text
        """
        param = {
            'tracking_number': num
        }

        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('9400111899561590599681')
print(result)
                                
                                     '9926933413'     // The tracking number you want to query
    );
    
    // Request Json
    $json = json_encode($param, JSON_UNESCAPED_UNICODE);
    $signature = strtoupper(md5($json.$key.$secret));
    
    $url = 'https://www.kd100.com/api/v1/carriers/detect';    // Carrier-auto-detection 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;


/**
 * Carrier Auto-detection
 *
 * @author https://www.kd100.com/
 *
 */
public class CarrierAutoDetection {

	private static final String URL = "https://www.kd100.com/api/v1/carriers/detect";
	//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 tracking_number = "9926933413";

		CarrierAutoDetection demo = new CarrierAutoDetection();
		String result = demo.getData(tracking_number);
		System.out.println(result);
	}
	


	public String getData(String tracking_number) {

		String param = "{\"tracking_number\": \"" + tracking_number + "\"}";

		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;
		}
	}
}