IDpack SDK - PHP cURL source codeIDpack SDK – PHP cURL source code

The IDpack SDK – PHP cURL source code is a basic example that demonstrates how to use PHP cURL to interact with the IDpack API. It provides a straightforward template for sending requests, managing authentication, and handling API responses. This script is ideal for developers seeking a quick and practical way to integrate the IDpack API into their applications.


// API USERNAME
$username = 'YOUR USERNAME';

// API USER PASSWORD
$password = 'YOUR PASSWORD';

// API URL
$url = 'https://api.idpack.cloud/producer/';

// SETUP REQUEST DATA
$data = array();

// ADD USER SECRET KEY
$data += ["user_secret_key" => 'YOUR USER SECRET KEY'];

// ADD PROJECT SECRET KEY
$data += ["project_secret_key" => 'YOUR PROJECT SECRET KEY'];

// SET API ACTION
$data += ["API_Action" => 'GET_record'];

// SPECIFY SEARCH CRITERIA (PRIMARY KEY)
$data += ["API_Search" => ["idc_id_number", '10000']];

// SET RESPONSE FORMAT (JSON OR XML)
$data += ["API_OutputFormat" => 'json'];

// DEFINE API VERSION
$data += ["API_Version" => '3.2.40'];

// CONVERT DATA TO JSON (PAYLOAD FOR API)
$data_string = json_encode($data);

// INITIALIZE cURL
$ch = curl_init();

if ($ch === false) {

    echo 'Failed to initialize';

} else {

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_TIMEOUT_MS, 2000);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_URL, $url);

    $headers = array(
        'Accept-Language: en-US',
        'Accept: application/json',
        'Content-Type: application/json',
        'Content-Length: '.strlen($data_string)
    );

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    // EXECUTE API CALL
    $content = curl_exec($ch);

    if ($content === false) {
        echo curl_error($ch).' '.curl_errno($ch);
    } else {
        $httpReturnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        if ($httpReturnCode != 200) {
            echo 'HTTP return code not 200. (Code '.$httpReturnCode.')';
        } else {
            echo $content;
        }
    }
}

To explore all the available actions, understand how to structure your API requests, and review detailed information about the JSON response format, please visit the IDpack API – Reference section. This comprehensive resource provides in-depth documentation, including examples of API calls, expected responses, and explanations of the parameters and their uses. It is an essential guide for developers working on integrating the IDpack API into their systems.