I’ve recently been developing a application for the car industry, to record vehicles, models, customer information, vehicle sales and storage of images etc. This is ASP.NET Blazor application which utilises Entity Framework Core, Microsoft Azure, Azure Web sites and Azure storage. One of the features I thought would really be interesting is for the car sales administrators to enter new vehicles into their stock and then dynamically have a component which allows them to query the vehicle information via the DVLA VES Web API.
Sometimes, to start with developing a component, I develop the component code outside of Blazor i.e. a Console application which can contains all the response structure, associated methods and calls the VES API with a HTTP client.
Now that I am finished with the basics of calling the VES web API, I can now expand this with all the necessary error handling e.g. HTTP error codes, and include this as a component within the Blazor application.
I’ve published the ASP.NET console application in my GitHub repo in the link below. You will need to request a VES API key and utilise your registrations, or set these as arguments in the console app, or just set a static string for this as it is in the current code.
If you prefer to perform a simpler test, I’ve provided a working PowerShell script below, you will just need to utilise your own API Key and set the registration as required.
$VehicleRegistrationNumber = "TE57VRN"
$APIKey = "[APIKEY]"
$DVLAURI = "https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles"
$Header = @{"x-api-key" = $APIKey}
$RequestBody = @{"registrationNumber"= $VehicleRegistrationNumber} | ConvertTo-Json
Invoke-RestMethod -Method Post -Uri $DVLAURI -Body $RequestBody -ContentType "application/json" -Headers $Header
Hi, do I have to upload all files from GitHub to my website to use the code for requesting and showing car details from DVLA VES API?
Hello,
Thank you for your comment.
The program, data classes, service definition and request body has been separated for a cleaner architecture. Depending on what you are building, you will still require an authentication key, this is in the program.cs under line public static string APIKey = “[Your API Key]”;
You must request the APIKey from the DVLA yourself. You can apply for one at this URL.
https://developer-portal.driver-vehicle-licensing.api.gov.uk/apis/vehicle-enquiry-service/vehicle-enquiry-service-description.html#vehicle-enquiry-service-ves-api-guide
I hope that helps.
Tejinder