This example demonstrates how to call the Key Detail API using PHP cURL, handle the HTTP response, and parse the JSON data to display key and device information.
<?php
$apiKey = 'YOUR_API_KEY';
$keyToCheck = 'KEY1-XXXX-XXXX-XXXX'; // Replace with actual key
$url = 'https://api.authtool.app/public/v1/key/' . $keyToCheck . '/detail';
$curl = curl_init();
curl_setopt_array($curl, [
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 => 'GET',
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . $apiKey
],
]);
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
$result = json_decode($response, true);
if ($httpCode === 200) {
$key = $result['key'];
$devices = $result['devices'];
echo "Activate Count: " . $key['activateCount'] . "/" . $key['activateLimit'] . "\n";
echo "Duration: " . $key['duration'] . " " . $key['unit'] . "\n";
foreach ($devices as $device) {
echo "Device ID: " . $device['uid'] . " Status: " . ($device['status'] ? 'Active' : 'Inactive') . "\n";
}
} else {
echo "Error: " . ($result['message'] ?? 'Unknown error') . "\n";
}
?>