Exemples de code
La même intégration en quatre langages : démarrer une identification, puis attendre le résultat. Ils utilisent la clé d’API de test ; en production, remplacez-la par votre certificat (Demander un certificat).
Node.js (18 ou plus)
const API = 'https://www.excelidapi.aikinggroup.com';
const headers = { 'Content-Type': 'application/json', 'X-Api-Key': process.env.EXCELID_API_KEY };
async function call(path, body) {
const r = await fetch(API + path, { method: 'POST', headers, body: JSON.stringify(body) });
const json = await r.json();
if (!r.ok) throw new Error(`${json.errorCode} : ${json.details}`);
return json;
}
const order = await call('/v1/auth', {
endUserIp: '196.28.245.10',
userVisibleData: Buffer.from('Connexion à Mon Service').toString('base64'),
});
while (true) {
const r = await call('/v1/collect', { orderRef: order.orderRef });
if (r.status === 'complete') { console.log(r.completionData.user); break; }
if (r.status === 'failed') throw new Error(r.hintCode);
await new Promise((ok) => setTimeout(ok, 2000));
}
Python 3
import base64, os, time
import requests
API = "https://www.excelidapi.aikinggroup.com"
HEADERS = {"X-Api-Key": os.environ["EXCELID_API_KEY"]}
def call(path, body):
r = requests.post(API + path, headers=HEADERS, json=body, timeout=15)
data = r.json()
if not r.ok:
raise RuntimeError(f"{data['errorCode']} : {data['details']}")
return data
order = call("/v1/auth", {
"endUserIp": "196.28.245.10",
"userVisibleData": base64.b64encode("Connexion à Mon Service".encode()).decode(),
})
while True:
result = call("/v1/collect", {"orderRef": order["orderRef"]})
if result["status"] == "complete":
print(result["completionData"]["user"])
break
if result["status"] == "failed":
raise RuntimeError(result["hintCode"])
time.sleep(2)
PHP 8
<?php
const API = 'https://www.excelidapi.aikinggroup.com';
function call(string $path, array $body): array {
$ch = curl_init(API . $path);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15,
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'X-Api-Key: ' . getenv('EXCELID_API_KEY')],
CURLOPT_POSTFIELDS => json_encode($body),
]);
$data = json_decode(curl_exec($ch), true);
if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) >= 400) {
throw new RuntimeException($data['errorCode'] . ' : ' . $data['details']);
}
return $data;
}
$order = call('/v1/auth', [
'endUserIp' => '196.28.245.10',
'userVisibleData' => base64_encode('Connexion à Mon Service'),
]);
while (true) {
$r = call('/v1/collect', ['orderRef' => $order['orderRef']]);
if ($r['status'] === 'complete') { print_r($r['completionData']['user']); break; }
if ($r['status'] === 'failed') { throw new RuntimeException($r['hintCode']); }
sleep(2);
}
Java 17 ou plus
import java.net.URI;
import java.net.http.*;
import java.util.Base64;
public class Essai {
static final String API = "https://www.excelidapi.aikinggroup.com";
static final HttpClient HTTP = HttpClient.newHttpClient();
static String call(String path, String json) throws Exception {
HttpRequest req = HttpRequest.newBuilder(URI.create(API + path))
.header("Content-Type", "application/json")
.header("X-Api-Key", System.getenv("EXCELID_API_KEY"))
.POST(HttpRequest.BodyPublishers.ofString(json)).build();
HttpResponse<String> res = HTTP.send(req, HttpResponse.BodyHandlers.ofString());
if (res.statusCode() >= 400) throw new RuntimeException(res.body());
return res.body();
}
public static void main(String[] args) throws Exception {
String text = Base64.getEncoder().encodeToString("Connexion à Mon Service".getBytes("UTF-8"));
String order = call("/v1/auth", "{\"endUserIp\":\"196.28.245.10\",\"userVisibleData\":\"" + text + "\"}");
// Extrayez orderRef avec votre bibliothèque JSON (Jackson, Gson…), puis :
String orderRef = order.replaceAll(".*\"orderRef\":\"([^\"]+)\".*", "$1");
while (true) {
String r = call("/v1/collect", "{\"orderRef\":\"" + orderRef + "\"}");
if (r.contains("\"status\":\"complete\"")) { System.out.println(r); break; }
if (r.contains("\"status\":\"failed\"")) throw new RuntimeException(r);
Thread.sleep(2000);
}
}
}
Ces exemples ne contiennent ni gestion des erreurs réseau ni reprises. Dans votre service, ajoutez-les, et annulez la demande avec /v1/cancel quand la personne quitte la page.