Skip to content

johnhazellautorepairs/MOT.NET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MOT.NET

Overview

MOT.NET is a .NET Core library which provides access to the DVSA's MOT history API.

As well as MOT tests, this API provides access to other vehicle data. These include registration date, cylinder capacity, fuel type and make and model.

Apply for API access

This API requires an API key. You may obtain an API key for your organisation by completing this application.

Installation

The library is available as "MOT.NET" on NuGet.

Install the package by running:

dotnet add package MOT.NET

Setup

MotTestClient requires an API key, specify it in the constructor as follows:

// Example API key, replace with yours. Keep it secret!
var apikey = "foobar";

// Initialise the MotTestClient.
IMotTestClient client = new MotTestClient(apikey);

If you prefer, you can provide the API key as a SecureString.

Queries

Once initialised, the library may query the API in three different ways:

By vehicle:

Vehicles are queried by registration. Use the Registration method to specify a registration, and FetchAsync to fetch records:

// IAsyncEnumerable of Vehicles, allowing asynchronous streaming of results.
IAsyncEnumerable<Vehicle> vehicles = client
    .Registration("F1") // Set the registration to query.
    .FetchAsync(); // Fetch the vehicle from the API service.

// Asynchronously iterate reulsts.
await foreach(Vehicle vehicle in vehicles) {
    // Output vehicle make.
    Console.WriteLine(vehicle.Make);
}

By page:

Records are grouped in pages of 400-500 each. Use the Page method to specify a page, and FetchAsync to fetch records:

// Used after a previous query has been run, clears parameters.
client.Clear();

IAsyncEnumerable<Vehicle> vehicles = client
    .Page(0) // Set the page to query.
    .FetchAsync();

await foreach(Vehicle vehicle in vehicles) {
    // Output the vehicle models.
    Console.WriteLine(vehicle.Model);
}

This method is useful for downloading all records. Continue to download these pages from zero until exhaustion after ~50,000 pages (server will return status 404).

Note: The API is rate limited to 10 requests per second, make sure not to exceed this.

By date and page:

Records are queryable by date, with 1440 pages per day (1 page per minute).

Use the Date method to set the date parameter, the Page method to set the page parameter, and the FetchAsync method to fetch records:

client.Clear();

IAsyncEnumerable<Vehicle> vehicles = client
    .Date(DateTime.Today) // Set the page to query (to today).
    .Page(720) // Set the page to query (720 = noon).
    .FetchAsync();

await foreach(Vehicle vehicle in vehicles) {
    // Output the vehicle engine size.
    Console.WriteLine(vehicle.EngineSize;
}

Invalid Queries

The Page parameter may be used with the Date parameter. However, the Registration parameter may not be used with any other parameter.

Conversely, the Date parameter may not be used on its own and must be used with the Page parameter.

The library will throw an InvalidParametersException when parameters are combined in any way which the API will not accept.

Exceptions

Some API error responses are represented by exceptions to improve usability. These are thrown by FetchAsync.

These are NoRecordsFoundException; thrown when no records are found for the given parameters and InvalidApiKeyException; thrown when the specified API key is not accepted by the API service.

FetchAsync throws HttpResponseException for all other response codes (except 200).

Thanks!

Your usage and support is greatly appreciated.

About

A .NET library for accessing the DVSA's MOT history API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages