Sample code for 30+ languages & platforms
Xbase++

DVLA Vehicle Enquiry Service

See more _Miscellaneous_ Examples

Demonstrates how to make a call to the DVLA Vehicle Enquiry API to get vehicle details of a specified vehicle. It uses the vehicle registration number as input to search and provide details of the vehicle.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cArtEndDate
LOCAL nCo2Emissions
LOCAL cColour
LOCAL nEngineCapacity
LOCAL cFuelType
LOCAL cMake
LOCAL nMarkedForExport
LOCAL cMonthOfFirstRegistration
LOCAL cMotStatus
LOCAL cRegistrationNumber
LOCAL nRevenueWeight
LOCAL cTaxDueDate
LOCAL cTaxStatus
LOCAL cTypeApproval
LOCAL cWheelplan
LOCAL nYearOfManufacture
LOCAL cEuroStatus
LOCAL cRealDrivingEmissions
LOCAL cDateOfLastV5CIssued

nSuccess := 0

//  This example assumes the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oHttp := CreateObject("Chilkat.Http")

//  Implements the following CURL command:

//  curl -X POST https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles \
//    -H "x-api-key: supplied API key" \
//    -H "Accept: application/json" \
//    -d '{"registrationNumber": "ABC1234"}'

//  Use the following online tool to generate HTTP code from a CURL command
//  Convert a cURL Command to HTTP Source Code

//  Use this online tool to generate code from sample JSON:
//  Generate Code to Create JSON

//  The following JSON is sent in the request body.

//  {
//    "registrationNumber": "ABC1234"
//  }

oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("registrationNumber", "ABC1234")

oHttp:SetRequestHeader("Accept", "application/json")
oHttp:SetRequestHeader("x-api-key", "supplied API key")

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", "https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles", oJson, "application/json", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oJson:destroy()
    oResp:destroy()
    RETURN
ENDIF

oSbResponseBody := CreateObject("Chilkat.StringBuilder")
oResp:GetBodySb(oSbResponseBody)
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0

? "Response Body:"
? oJResp:Emit()

nRespStatusCode := oResp:StatusCode
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
    ? "Response Header:"
    ? oResp:Header
    ? "Failed."
    oHttp:destroy()
    oJson:destroy()
    oResp:destroy()
    oSbResponseBody:destroy()
    oJResp:destroy()
    RETURN
ENDIF

//  Sample JSON response:
//  (Sample code for parsing the JSON response is shown below)

//  {
//    "artEndDate": "2025-02-28",
//    "co2Emissions": 135,
//    "colour": "BLUE",
//    "engineCapacity": 2494,
//    "fuelType": "PETROL",
//    "make": "ROVER",
//    "markedForExport": false,
//    "monthOfFirstRegistration": "2004-12",
//    "motStatus": "No details held by DVLA",
//    "registrationNumber": "ABC1234",
//    "revenueWeight": 1640,
//    "taxDueDate": "2007-01-01",
//    "taxStatus": "Untaxed",
//    "typeApproval": "N1",
//    "wheelplan": "NON STANDARD",
//    "yearOfManufacture": 2004,
//    "euroStatus": "EURO 6 AD",
//    "realDrivingEmissions": "1",
//    "dateOfLastV5CIssued": "2016-12-25"
//  }

//  Sample code for parsing the JSON response...
//  Use the following online tool to generate parsing code from sample JSON:
//  Generate Parsing Code from JSON

cArtEndDate := oJResp:StringOf("artEndDate")
nCo2Emissions := oJResp:IntOf("co2Emissions")
cColour := oJResp:StringOf("colour")
nEngineCapacity := oJResp:IntOf("engineCapacity")
cFuelType := oJResp:StringOf("fuelType")
cMake := oJResp:StringOf("make")
nMarkedForExport := oJResp:BoolOf("markedForExport")
cMonthOfFirstRegistration := oJResp:StringOf("monthOfFirstRegistration")
cMotStatus := oJResp:StringOf("motStatus")
cRegistrationNumber := oJResp:StringOf("registrationNumber")
nRevenueWeight := oJResp:IntOf("revenueWeight")
cTaxDueDate := oJResp:StringOf("taxDueDate")
cTaxStatus := oJResp:StringOf("taxStatus")
cTypeApproval := oJResp:StringOf("typeApproval")
cWheelplan := oJResp:StringOf("wheelplan")
nYearOfManufacture := oJResp:IntOf("yearOfManufacture")
cEuroStatus := oJResp:StringOf("euroStatus")
cRealDrivingEmissions := oJResp:StringOf("realDrivingEmissions")
cDateOfLastV5CIssued := oJResp:StringOf("dateOfLastV5CIssued")

oHttp:destroy()
oJson:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()