IDpack SDK - PHP cURL source codeIDpack SDK - Code source PHP cURL

L’exemple de code IDpack SDK – Code source PHP cURL montre comment utiliser PHP cURL pour interagir avec l’API IDpack. Il offre un gabarit simple pour envoyer des requêtes, gérer l’authentification et traiter les réponses de l’API. Ce script est idéal pour les développeurs à la recherche d’une méthode rapide et pratique pour intégrer l’API IDpack à leurs applications.

 // NOM D’UTILISATEUR API $username = 'YOUR USERNAME'; // MOT DE PASSE UTILISATEUR API $password = 'YOUR PASSWORD'; // URL DE L’API $url = 'https://api.idpack.cloud/producer/'; // CONFIGURATION DES DONNÉES DE REQUÊTE $data = array(); // AJOUTER LA CLÉ SECRÈTE UTILISATEUR $data += ["user_secret_key" => 'YOUR USER SECRET KEY']; // AJOUTER LA CLÉ SECRÈTE DU PROJET $data += ["project_secret_key" => 'YOUR PROJECT SECRET KEY']; // DÉFINIR L’ACTION API $data += ["API_Action" => 'GET_record']; // SPÉCIFIER LES CRITÈRES DE RECHERCHE (CLÉ PRIMAIRE) $data += ["API_Search" => ["idc_id_number", '10000']]; // CHOISIR LE FORMAT DE RÉPONSE (JSON OU XML) $data += ["API_OutputFormat" => 'json']; // DÉFINIR LA VERSION DE L’API $data += ["API_Version" => '3.2.40']; // CONVERTIR LES DONNÉES EN JSON (PAYLOAD DE L’API) $data_string = json_encode($data); // INITIALISER cURL $ch = curl_init(); if ($ch === false) { echo 'Échec de l’initialisation'; } 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); // EXÉCUTER L’APPEL API $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 'Code de retour HTTP différent de 200. (Code '.$httpReturnCode.')'; } else { echo $content; } } } 

Pour découvrir toutes les actions disponibles, comprendre comment structurer vos requêtes API et consulter des informations détaillées sur le format de réponse JSON, veuillez visiter la section IDpack API - Référence. Cette ressource complète offre une documentation approfondie, comprenant des exemples d’appels API, de réponses attendues ainsi que des explications sur les paramètres et leur utilisation. Il s’agit d’un guide essentiel pour les développeurs souhaitant intégrer l’API IDpack à leurs systèmes.