Free used-car check for Ghana: a tool built on US federal APIs
Most used cars sold in Ghana come from the US. This post describes how a free tool was built that checks recalls, owner complaints and crash ratings by VIN, and what happened where the data sources did not agree with each other.
Most used cars sold in Ghana are bought at US auctions and shipped through the port of Tema. At a roadside car dealer or in an online listing, the seller says "accident-free, low mileage, one owner." The Ghana Standards Authority has announced that importing used vehicles aged 15 years and older will be banned from 1 October 2026. This decision pushed buyers to find out the real model year of a car, not the one written in the listing.
The tool described in this post is a free check page where users in Ghana paste a VIN and see the car's real details, recalls, owner complaints and crash ratings. The data comes from the NHTSA vPIC, NHTSA recall and complaint services and EPA fueleconomy.gov in the US, plus the current fuel price in Ghana. Fuel cost is shown as a monthly estimate in cedis. All of these sources are public data that do not require an API key. The real problems did not come from the APIs themselves, but from the points where they were combined.
Cleaning the VIN before trusting it
Users mostly type the VIN from a photo of the label on the windshield, so characters like 0 and O, or 1 and I, are often confused. The VIN standard leaves out the letters I, O and Q precisely to avoid this confusion. For that reason, in a 17-character input you can safely convert these letters to digits:
public static function cleanVin(?string $vin): ?string
{
$vin = strtoupper(preg_replace('/[^A-Za-z0-9]/', '', (string) $vin));
if (strlen($vin) === 17) {
$vin = strtr($vin, ['I' => '1', 'O' => '0', 'Q' => '0']);
}
return preg_match('/^[A-HJ-NPR-Z0-9]{17}$/', $vin) ? $vin : null;
}
This small fix turned a large share of the "invalid VIN" errors into real results.
The check digit is not meaningful for every car
The ninth character of a VIN is a check digit. It is calculated from the remainder of a weighted sum of the other characters divided by 11. In the first version, when this digit did not match, the car was flagged with "this VIN may be fake." That was wrong. The check digit is mandatory only for vehicles made for the North American market (those whose VIN starts with a digit from 1 to 5). Many cars made for Japan, Europe or the Gulf do not use this digit at all. A significant share of the cars arriving in Ghana fall into this group.
So the warning is strict only for VINs of North American origin, and for the others it is shown as an informational note. A tool that gives false alarms on half of the cars it checks is soon ignored. A false alarm is also an error.
NHTSA is inconsistent with model names
The biggest surprise in the project was that the VIN decoder, the recall service and the complaint service did not always write the same model the same way. A few examples:
- The VIN decoder gives the model as "Sierra" and the series as "1500." Recalls are registered under the name "SIERRA 1500."
- The Lexus "RX 350" appears as "RX350" in the recall database.
- Recalls use "C300," while complaints use "C-CLASS."
We noticed this problem on a 2017 GMC Sierra. The page showed "0 recalls," but NHTSA had 6 recalls and 433 complaints recorded for this vehicle. Telling someone "no recalls" is worse than not doing a vehicle check at all.
The solution was a fallback chain of names that is used only when no result is found with the first name:
$adaylar = array_unique([
$model, // "Sierra"
$model . ' ' . $seri, // "Sierra 1500"
$normalize($model), // spaces and punctuation stripped
]);
foreach ($adaylar as $aday) {
$sonuc = $this->geriCagirmalariAra($marka, $aday, $yil);
if (!empty($sonuc)) {
return ['model' => $aday, 'veri' => $sonuc];
}
}
return ['model' => $model, 'veri' => null, 'eksik' => true];
The name under which the recall was found is saved and also used in the complaint query. This way the two sections of the report describe the same vehicle. The lesson can be summed up like this: do not assume that endpoints from the same provider share a common identifier. Test with real, messy data, especially for pickup trucks and luxury trim packages.
Slow endpoints and caching
The complaint service can take around 9 seconds for a popular model. If all requests are made one after another, the report exceeds 15 seconds, and on mobile data this makes the page feel broken. Three changes were made for this:
- Parallel requests. Recalls, crash ratings and the EPA model list are sent at the same time because they do not depend on each other. In the second round, the data that needs the result of the first round (crash rating details and EPA engine options) is fetched.
- Different cache durations. Complete results are kept for 7 days, while partial results, where some source returned an error, are kept for only 15 minutes. This way, a brief problem at NHTSA does not leave a broken result in place for a whole week.
- Overnight cache warming. The system has 312 model pages made up of popular models from 2010 to 2022. A scheduled job caches 24 model years per hour between 01:00 and 05:30. By morning, the frequently searched pages are already ready.
In the interface, when the "Check" button is pressed, step messages such as "Checking recalls" are shown instead of an empty spinning icon. When people can see what is happening, they are more patient while waiting.
Building a shared history without giving up privacy
US data cannot catch the most common fraud in Ghana. Examples include the same car being relisted with lower mileage, or the same photos being used by several different sellers. For this reason, every query creates a "seen" record: the VIN, the date, and the mileage, model year and price declared by the seller. Later users see the earlier records for the same VIN, along with these warnings:
- If the mileage dropped by more than 1,000 km between two queries, the odometer may have been rolled back.
- If the same VIN is being sold from different phone numbers, photos may have been stolen and reused.
- If the declared model year keeps changing.
For this, the seller's phone number and the IP address of the person doing the check are stored as HMAC, not as plain text:
public static function hash(string $value): string
{
return hash_hmac('sha256', $value, 'car-vin|' . config('app.key'));
}
With this method, you can count and compare different sellers, but you cannot read the number back. Using the secret key is essential. Because phone numbers live in a small space, an unkeyed SHA-256 digest can be brute-forced in a few minutes. The rollback check simply walks through the records by date and tracks the highest mileage seen up to that point. Since only one record is kept per visitor, VIN and day, it is not possible to inflate the history by reloading the page over and over.
Cars without a VIN
Many cars made for the Japanese market have a chassis number instead of a VIN. These numbers consist of a model code, a dash and a serial number. The NHTSA cannot decode this format, and it also cannot fully decode some VINs of Gulf and European origin. The tool accepts this chassis format and runs the report based on the make, model and year declared by the seller. It also states clearly which parts come from the VIN and which come from the seller's declaration. An incomplete result that clearly states its source still helps someone standing next to the car.
Key takeaways
- Recall, complaint, crash rating and fuel data are offered for free without a key; official public APIs should not be underestimated.
- Errors mostly appear where the systems meet; it is necessary to test with real inputs from your own market.
- In a safety-focused tool, a false "clean" result is the most dangerous error; saying "this check could not be completed" is more honest than saying "0 recalls."
- Partial results should be cached briefly, and complete results for longer.
- If personal data such as phone numbers is stored with a keyed HMAC, it is still possible to build a shared history without collecting data in the plain.
When to use it
This approach works in any application that works with public data and where users make safety decisions based on it, especially when different sources are combined. However, before results are shown, you should test whether the data sources are consistent with each other, and missing data should be stated openly rather than hidden. If you are not familiar with the VIN standard, chassis formats and model naming conventions used in your market, testing with real user data before publishing your first version is at least as important as writing the code.
Comments (0)
No comments yet; be the first.
Leave a comment