DEV Community

Abe Darwish for CarsXE

Posted on • Updated on

Decoding A Vehicle License Plate With An API

If you're building an application that involves vehicles whether it's an AI solution or mobile parking application a VIN is one of the most powerful pieces of information you can attain to learn more about the vehicle and its owner.

Every vehicle on the road has a unique vehicle identification number (VIN) but that number is usually small and hidden under the windshield. Furthermore, most car owners don't know their vehicle's VIN let alone that they have one.

One thing that is visible and every vehicle owner knows about is a vehicle's license plate. The license plate, like the VIN, is unique but it changes from owner to owner.

In this tutorial we're going to use the license plate number of a vehicle to retrieve the VIN, make, model, year and a sample image of the vehicle.

Retrieve Data Using License Plate Number

We'll use the CarsXE Plate Decoder API and it's documentation to retrieve vehicle information using the license plate number.

Let's say I'm building a mobile parking application. In the app, I require the user to give me the license plate number and state of the vehicle.

The user provides the following information:

  • 36619HT - Plate number
  • MD - Two-character state code for Maryland

So I need to make an HTTP GET request to the API requesting this data. I love JavaScript so I'll give an example using the request package in my NodeJS server application. Here's what I need to make the request:

  1. Get a unique CarsXE API Key (by creating an account and adding a payment method)
  2. Make the request to the endpoint http://api.carsxe.com/platedecoder?
  3. Set our plate query to our value: plate=36619HT
  4. Set our state query to our value: state=MD
  5. Set our key query to our CarsXE API Key: key=<CarsXE_API_Key>
  6. Set our format query to either json or xml depending on how we'd like the format of the response to be.

Ok, let's make the request!

var request = require('request');

const r = "http://api.carsxe.com/platedecoder?plate=36619HT&state=MD&format=json&key=<CarsXE_API_Key>";

request(r, function (error, response, body) {
  console.log('error:', error); // Print the error if one occurred
  console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  console.log('body:', body); // Print the HTML for the Google homepage.
});
Enter fullscreen mode Exit fullscreen mode

Ok, let's see what the response of the API looks like!

{
    "success": true,
    "vin": "4T1BF22K5WU057633",
    "imageUrl": "https://api.carsxe.com/pic?image=@VG95b3RhIENhbXJ5IENFIC8gTEUgLyBYTEU=",
    "assembly": "United States",
    "Description": "Toyota Camry CE / LE / XLE",
    "RegistrationYear": "1998",
    "CarMake": "Toyota",
    "CarModel": "Camry CE / LE / XLE",
    "BodyStyle": "Sedan 4D",
    "EngineSize": "3.0L V6 EFI"
}
Enter fullscreen mode Exit fullscreen mode

Isn't that amazing! Just from knowing the plate number and state which we required the user to enter we were capable of retrieving that the vehicle the user just parked is a 1998 Toyota Camry with a 3.0L V6 EFI engine.

Even more impressive is that we were able to pull the vehicle VIN for that specific vehicle which we can use to pull the vehicle's history, specs, and market value. We can know the owner of the vehicle, whether it's stolen, whether it's been in any accidents, or there are any liens on the vehicle and more.

I hope you can benefit from this tutorial and API as much as I have!

Top comments (8)

Collapse
 
bharti_kumawat profile image
Bharti Kumawat

I am trying to do it with php curl. Its working fine with command line but its returning an error when I execute it via php.

My error is: Failed to connect to domain.com port 443: Connection refused

Please help to resolve this issue.

Thanks

Collapse
 
katnel20 profile image
Katie Nelson

I think you need to handle cases where the plate characters look similar. Like the letter O and the number 0 look very much alike. Something like a regular expression input where it could be [0|O].

Collapse
 
idarwishman profile image
Abe Darwish

This is a great point. Some states such as Massachusetts allow the letter O and the number 0 on the same plate while in North Carolina only the number 0 is allowed. If I’m not mistaken the API handles this on their side. Could you expand on your point, I’d love to know more about what you’re thinking?

Collapse
 
katnel20 profile image
Katie Nelson

If I’m going by a car and I can’t make the plate exactly, there should be a way to enter a partial plate or choices for a letter/digit. Just like in a SQL query, you can do a LIKE clause.

Collapse
 
ak_3434 profile image
Oleksandr Kryvenko • Edited

Hi! I am a bit confused about pricing, could you advise how much does Vehicle Plate Decoder AP. As I can see the price is 0.45 but, is it for one request or for 1k?

Some comments may only be visible to logged-in visitors. Sign in to view all comments.