Here is everything you need to look up a number plate from PHP. The example only uses what comes with PHP (cURL), so there is nothing to install.
The lookup
<?php
function lookupPlate(string $country, string $plate): ?array
{
$key = getenv('PLATERUNNER_KEY');
$plate = strtoupper(preg_replace('/[\s-]/', '', $plate));
$url = "https://api.platerunner.dk/v1/plates/{$country}/" . rawurlencode($plate);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
CURLOPT_HTTPHEADER => ["Authorization: Bearer {$key}"],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status === 404) {
return null; // the plate does not exist
}
if ($status !== 200 || $body === false) {
throw new RuntimeException("PlateRunner responded {$status}");
}
return json_decode($body, true);
}
$car = lookupPlate('DK', 'AB 12 345');
echo $car ? "{$car['make']} {$car['model']}" : 'Not found';
Put the key in an environment variable (PLATERUNNER_KEY), never directly in the code.
Save the response
A vehicle’s data rarely changes. Save the response in your own database when you have looked up a plate, so the same vehicle does not cost another lookup next time. It saves both time and lookups.
Errors you need to handle
- 404: the plate does not exist. Show a friendly message and let the user enter the vehicle manually.
- 429: this month’s lookups are used, or too many arrived at once. Try again later, or upgrade the plan.
- 401: the key is missing or incorrect.
See getting started for every field in the response.