Entegrasyon örnekleri

Aşağıdaki örneklerde BASE_URL ve API_KEY değerlerini kendi ortamınıza göre değiştirin.

Örnekler async modu kullanır. Canlı doğrulama sonuçları çoğunlukla 1-2 dakika içinde gelir; sonucu webhook ile almanızı, polling'i ise arka plandaki bir kuyruk işinde yapmanızı öneririz. Kullanıcı akışınızı kilitlemeyen yapı için entegrasyon rehberine bakın.

PHP / Laravel — async istek

use Illuminate\Support\Facades\Http;

$baseUrl = config('services.kimlikapi.base_url');
$key = config('services.kimlikapi.api_key');

$response = Http::withToken($key)
    ->acceptJson()
    ->post("{$baseUrl}/v1/verify", [
        'id_number' => '10000000146',
        'first_name' => 'Test',
        'last_name' => 'Kullanici',
        'birth_date' => '1990-01-15',
        'mode' => 'async',
        'reference_id' => 'order-123',
    ]);

// 202: status=processing, sonuç webhook ile gelir.
// 200: önbellekte sonuç varsa status=completed ve result döner.
$requestId = $response->json('request_id');

PHP / Laravel — kuyruk işinde polling

// Webhook alamıyorsanız: talebi gönderdikten sonra bu işi 30 sn
// gecikmeyle kuyruğa bırakın; sonuç yoksa kendini yeniden kuyruğa alır.
class CheckVerificationStatus implements ShouldQueue
{
    use Queueable;

    public function __construct(public string $requestId, public int $checks = 0) {}

    public function handle(): void
    {
        $status = Http::withToken(config('services.kimlikapi.api_key'))
            ->get(config('services.kimlikapi.base_url')."/v1/requests/{$this->requestId}")
            ->json();

        if ($status['status'] === 'processing') {
            $delay = $this->checks < 10 ? 45 : 300;
            self::dispatch($this->requestId, $this->checks + 1)->delay(now()->addSeconds($delay));

            return;
        }

        // completed / failed: kendi kaydınızı güncelleyin
    }
}

CheckVerificationStatus::dispatch($requestId)->delay(now()->addSeconds(30));

Node.js (fetch)

const response = await fetch(`${process.env.TCDOGRULA_BASE_URL}/v1/verify`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.TCDOGRULA_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    id_number: '10000000146',
    first_name: 'Test',
    last_name: 'Kullanici',
    birth_date: '1990-01-15',
    mode: 'async',
    reference_id: 'order-123',
  }),
});

const data = await response.json();
// response.status === 202 → data.status === 'processing'; sonucu webhook ile alın
console.log(response.headers.get('x-request-id'), data);

Python (requests)

import os
import requests

base = os.environ['TCDOGRULA_BASE_URL']
key = os.environ['TCDOGRULA_API_KEY']
headers = {'Authorization': f'Bearer {key}'}

r = requests.post(
    f'{base}/v1/verify',
    headers=headers,
    json={
        'id_number': '10000000146',
        'first_name': 'Test',
        'last_name': 'Kullanici',
        'birth_date': '1990-01-15',
        'mode': 'async',
        'reference_id': 'order-123',
    },
    timeout=15,
)
# 202 → status: processing; sonucu webhook veya polling ile alın
print(r.status_code, r.json()['request_id'])

cURL — tüm uç noktalar

POST /v1/verify

curl -sS -X POST "$BASE_URL/v1/verify" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"id_number":"10000000146","first_name":"Test","last_name":"Kullanici","birth_date":"1990-01-15","mode":"async"}'

GET /v1/requests/{request_id}

curl -sS "$BASE_URL/v1/requests/$REQUEST_ID" \
  -H "Authorization: Bearer $API_KEY"

GET /v1/account/credits

curl -sS "$BASE_URL/v1/account/credits" \
  -H "Authorization: Bearer $API_KEY"

GET /v1/account/usage

curl -sS "$BASE_URL/v1/account/usage" \
  -H "Authorization: Bearer $API_KEY"