.NET Quickstart Guide
Get started with CarsXE's .NET SDK to integrate comprehensive vehicle data into your .NET applications.
The CarsXE .NET SDK provides a simple and powerful way to integrate vehicle data into your .NET applications. This guide will help you get started quickly.
For more information, see the package on NuGet.
Installation
Install the CarsXE .NET package using NuGet:
dotnet add package CarsXE
Setup
First, import the CarsXE client and initialize it with your API key:
Program.cs
using carsxe;
string API_KEY = "YOUR_API_KEY";
CarsXE carsxe = new CarsXE(API_KEY);
Basic Usage
VIN Specifications
Program.cs
string vin = "WBAFR7C57CC811956";
try
{
var specs = carsxe.Specs(new Dictionary<string, string> { { "vin", vin } }).Result;
Console.WriteLine("API Response:");
Console.WriteLine(specs.RootElement.GetProperty("input").GetProperty("vin").ToString());
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
International VIN Decoder
Program.cs
try
{
var intvin = carsxe.InternationalVinDecoder(new Dictionary<string, string>
{
{ "vin", "WF0MXXGBWM8R43240" }
}).Result;
Console.WriteLine(intvin);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Market Value
Program.cs
try
{
var marketvalue = carsxe.MarketValue(new Dictionary<string, string>
{
{ "vin", "WBAFR7C57CC811956" }
}).Result;
Console.WriteLine(marketvalue);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Vehicle History
Program.cs
try
{
var history = carsxe.History(new Dictionary<string, string>
{
{ "vin", "WBAFR7C57CC811956" }
}).Result;
Console.WriteLine(history);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
License Plate Decoder
Program.cs
try
{
var decodedPlate = carsxe.PlateDecoder(new Dictionary<string, string>
{
{ "plate", "7XER187" },
{ "state", "CA" },
{ "country", "US" }
}).Result;
Console.WriteLine(decodedPlate);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Vehicle Images
Program.cs
try
{
var images = carsxe.Images(new Dictionary<string, string>
{
{ "make", "BMW" },
{ "model", "X5" },
{ "year", "2019" }
}).Result;
Console.WriteLine(images);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Vehicle Recalls
Program.cs
try
{
var recalls = carsxe.Recalls(new Dictionary<string, string>
{
{ "vin", "1C4JJXR64PW696340" }
}).Result;
Console.WriteLine(recalls);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Plate Image Recognition
Program.cs
try
{
var plateimg = carsxe.PlateImageRecognition(
"https://api.carsxe.com/img/apis/plate_recognition.JPG"
).Result;
Console.WriteLine(plateimg);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
VIN OCR from Image
Program.cs
try
{
var vinocr = carsxe.VinOcr(
"https://api.carsxe.com/img/apis/plate_recognition.JPG"
).Result;
Console.WriteLine(vinocr);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Year-Make-Model Search
Program.cs
try
{
var yymm = carsxe.YearMakeModel(new Dictionary<string, string>
{
{ "year", "2012" },
{ "make", "BMW" },
{ "model", "5 Series" }
}).Result;
Console.WriteLine(yymm);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
OBD Code Decoder
Program.cs
try
{
var obdcode = carsxe.ObdCodesDecoder(new Dictionary<string, string>
{
{ "code", "P0115" }
}).Result;
Console.WriteLine(obdcode);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Error Handling
The SDK provides comprehensive error handling:
ErrorHandling.cs
using carsxe;
CarsXE carsxe = new CarsXE("YOUR_API_KEY");
try
{
var result = carsxe.Specs(new Dictionary<string, string>
{
{ "vin", "INVALID_VIN" }
}).Result;
}
catch (Exception ex)
{
// Handle different types of errors
Console.WriteLine($"Error: {ex.Message}");
// You can check for specific error types or status codes
// depending on how the SDK throws exceptions
}
Environment Variables
Store your API key securely using environment variables:
appsettings.json
{
"CarsXE": {
"ApiKey": "your_api_key_here"
}
}
Program.cs
using carsxe;
var builder = WebApplication.CreateBuilder(args);
// Configure CarsXE service
builder.Services.AddSingleton<CarsXE>(sp =>
new CarsXE(builder.Configuration["CarsXE:ApiKey"]));
Available Endpoints
Method | Description |
---|---|
carsxe.Specs(new Dictionary<string, string> { { "vin", vin } }) | Decode VIN & get full vehicle specifications |
carsxe.InternationalVinDecoder(new Dictionary<string, string> { { "vin", vin } }) | Decode VIN with worldwide support |
carsxe.PlateDecoder(new Dictionary<string, string> { { "plate", plate }, { "state", state }, { "country", country } }) | Decode license plate info |
carsxe.MarketValue(new Dictionary<string, string> { { "vin", vin } }) | Estimate vehicle market value based on VIN |
carsxe.History(new Dictionary<string, string> { { "vin", vin } }) | Retrieve vehicle history |
carsxe.Images(new Dictionary<string, string> { { "make", make }, { "model", model }, { "year", year } }) | Fetch images by make, model, year, trim |
carsxe.Recalls(new Dictionary<string, string> { { "vin", vin } }) | Get safety recall data for a VIN |
carsxe.PlateImageRecognition(imageUrl) | Read & decode plates from images |
carsxe.VinOcr(imageUrl) | Extract VINs from images using OCR |
carsxe.YearMakeModel(new Dictionary<string, string> { { "year", year }, { "make", make }, { "model", model } }) | Query vehicle by year, make, model and trim |
carsxe.ObdCodesDecoder(new Dictionary<string, string> { { "code", code } }) | Decode OBD error/diagnostic codes |
Start building powerful automotive applications with CarsXE's .NET SDK!