Unicode C++
Unicode C++
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 Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
bool success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW 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"
// }
CkJsonObjectW json;
json.UpdateString(L"registrationNumber",L"ABC1234");
http.SetRequestHeader(L"Accept",L"application/json");
http.SetRequestHeader(L"x-api-key",L"supplied API key");
CkHttpResponseW resp;
success = http.HttpJson(L"POST",L"https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles",json,L"application/json",resp);
if (success == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
CkStringBuilderW sbResponseBody;
resp.GetBodySb(sbResponseBody);
CkJsonObjectW jResp;
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",jResp.emit());
int respStatusCode = resp.get_StatusCode();
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",resp.header());
wprintf(L"Failed.\n");
return;
}
// 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
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
const wchar_t *artEndDate = jResp.stringOf(L"artEndDate");
int co2Emissions = jResp.IntOf(L"co2Emissions");
const wchar_t *colour = jResp.stringOf(L"colour");
int engineCapacity = jResp.IntOf(L"engineCapacity");
const wchar_t *fuelType = jResp.stringOf(L"fuelType");
const wchar_t *make = jResp.stringOf(L"make");
bool markedForExport = jResp.BoolOf(L"markedForExport");
const wchar_t *monthOfFirstRegistration = jResp.stringOf(L"monthOfFirstRegistration");
const wchar_t *motStatus = jResp.stringOf(L"motStatus");
const wchar_t *registrationNumber = jResp.stringOf(L"registrationNumber");
int revenueWeight = jResp.IntOf(L"revenueWeight");
const wchar_t *taxDueDate = jResp.stringOf(L"taxDueDate");
const wchar_t *taxStatus = jResp.stringOf(L"taxStatus");
const wchar_t *typeApproval = jResp.stringOf(L"typeApproval");
const wchar_t *wheelplan = jResp.stringOf(L"wheelplan");
int yearOfManufacture = jResp.IntOf(L"yearOfManufacture");
const wchar_t *euroStatus = jResp.stringOf(L"euroStatus");
const wchar_t *realDrivingEmissions = jResp.stringOf(L"realDrivingEmissions");
const wchar_t *dateOfLastV5CIssued = jResp.stringOf(L"dateOfLastV5CIssued");
}