Sample code for 30+ languages & platforms
Lua

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 Lua Downloads

Lua
local chilkat = require("chilkat")

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

local http = chilkat.Http.new()

-- 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"
-- }

local json = chilkat.JsonObject.new()
json:update_string("registrationNumber", "ABC1234")

http:set_request_header("Accept", "application/json")
http:set_request_header("x-api-key", "supplied API key")

local resp = chilkat.HttpResponse.new()
local success = http:http_json("POST", "https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles", json, "application/json", resp)
if not success then
    print(http.last_error_text)
    return
end

local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(resp.header)
    print("Failed.")
    return
end

-- 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

local artEndDate = jResp:string_of("artEndDate")
local co2Emissions = jResp:int_of("co2Emissions")
local colour = jResp:string_of("colour")
local engineCapacity = jResp:int_of("engineCapacity")
local fuelType = jResp:string_of("fuelType")
local make = jResp:string_of("make")
local markedForExport = jResp:bool_of("markedForExport")
local monthOfFirstRegistration = jResp:string_of("monthOfFirstRegistration")
local motStatus = jResp:string_of("motStatus")
local registrationNumber = jResp:string_of("registrationNumber")
local revenueWeight = jResp:int_of("revenueWeight")
local taxDueDate = jResp:string_of("taxDueDate")
local taxStatus = jResp:string_of("taxStatus")
local typeApproval = jResp:string_of("typeApproval")
local wheelplan = jResp:string_of("wheelplan")
local yearOfManufacture = jResp:int_of("yearOfManufacture")
local euroStatus = jResp:string_of("euroStatus")
local realDrivingEmissions = jResp:string_of("realDrivingEmissions")
local dateOfLastV5CIssued = jResp:string_of("dateOfLastV5CIssued")