Sample code for 30+ languages & platforms
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

Unicode C
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *artEndDate;
    int co2Emissions;
    const wchar_t *colour;
    int engineCapacity;
    const wchar_t *fuelType;
    const wchar_t *make;
    BOOL markedForExport;
    const wchar_t *monthOfFirstRegistration;
    const wchar_t *motStatus;
    const wchar_t *registrationNumber;
    int revenueWeight;
    const wchar_t *taxDueDate;
    const wchar_t *taxStatus;
    const wchar_t *typeApproval;
    const wchar_t *wheelplan;
    int yearOfManufacture;
    const wchar_t *euroStatus;
    const wchar_t *realDrivingEmissions;
    const wchar_t *dateOfLastV5CIssued;

    success = FALSE;

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

    http = CkHttpW_Create();

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

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"registrationNumber",L"ABC1234");

    CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");
    CkHttpW_SetRequestHeader(http,L"x-api-key",L"supplied API key");

    resp = CkHttpResponseW_Create();
    success = CkHttpW_HttpJson(http,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",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);
    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkHttpResponseW_Dispose(resp);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        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.

    artEndDate = CkJsonObjectW_stringOf(jResp,L"artEndDate");
    co2Emissions = CkJsonObjectW_IntOf(jResp,L"co2Emissions");
    colour = CkJsonObjectW_stringOf(jResp,L"colour");
    engineCapacity = CkJsonObjectW_IntOf(jResp,L"engineCapacity");
    fuelType = CkJsonObjectW_stringOf(jResp,L"fuelType");
    make = CkJsonObjectW_stringOf(jResp,L"make");
    markedForExport = CkJsonObjectW_BoolOf(jResp,L"markedForExport");
    monthOfFirstRegistration = CkJsonObjectW_stringOf(jResp,L"monthOfFirstRegistration");
    motStatus = CkJsonObjectW_stringOf(jResp,L"motStatus");
    registrationNumber = CkJsonObjectW_stringOf(jResp,L"registrationNumber");
    revenueWeight = CkJsonObjectW_IntOf(jResp,L"revenueWeight");
    taxDueDate = CkJsonObjectW_stringOf(jResp,L"taxDueDate");
    taxStatus = CkJsonObjectW_stringOf(jResp,L"taxStatus");
    typeApproval = CkJsonObjectW_stringOf(jResp,L"typeApproval");
    wheelplan = CkJsonObjectW_stringOf(jResp,L"wheelplan");
    yearOfManufacture = CkJsonObjectW_IntOf(jResp,L"yearOfManufacture");
    euroStatus = CkJsonObjectW_stringOf(jResp,L"euroStatus");
    realDrivingEmissions = CkJsonObjectW_stringOf(jResp,L"realDrivingEmissions");
    dateOfLastV5CIssued = CkJsonObjectW_stringOf(jResp,L"dateOfLastV5CIssued");


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkHttpResponseW_Dispose(resp);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }