DEV Community

KeyDelivery Support for KeyDelivery

Posted on

Free Carrier Auto-detection API - PHP Demo

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.

Source: API Doc

<?php

    $url = 'https://www.kd100.com/api/v1/carriers/detect';
    $API_Key = ''; # You can find your ApiKey on https://app.kd100.com/api-managment
    $Secret = ''; # You can find your Secret on https://app.kd100.com/api-managment 

    $param = array(
        'tracking_number' => '285075106552'
    );
    $data = json_encode($param);

    $signature = strtoupper(md5($data . $API_Key . $Secret));

    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => $data,
        CURLOPT_HTTPHEADER => array(
            'API-Key: ' . $API_Key,
            'signature: ' . $signature,
            'Content-Type: application/json'
        ),
    ));
    $response = curl_exec($curl);
    curl_close($curl);
    echo $response;
?>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)