Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) UK Vehicle Data VRM LookupDemonstrates how to query the UK Vehicle Data VRM online API's. (See https://ukvehicledata.co.uk/)
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Rest, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var rest: HCkRest; bAutoReconnect: Boolean; success: Boolean; jsonResponseStr: PWideChar; json: HCkJsonObject; numBatteries: Integer; i: Integer; begin // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. rest := CkRest_Create(); // Connect using TLS. bAutoReconnect := True; success := CkRest_Connect(rest,'uk1.ukvehicledata.co.uk',443,True,bAutoReconnect); if (success <> True) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; // Replace UKVD-API-KEY with your actual API KEY, // which looks something like "abcdb1234-0abc-1235-abcf-1234c3d1abcd" CkRest_putAuthorization(rest,'ukvd-ipwhitelist UKVD-API-KEY'); // Replace "ABCDE" with a real VRM... CkRest_AddQueryParam(rest,'key_vrm','ABCDE'); // Add the Content-Type HTTP request header. // success = rest.AddHeader("Content-Type","application/json; charset=UTF-8"); // This request gets vehicle data. // See below for a request to get battery data. jsonResponseStr := CkRest__fullRequestNoBody(rest,'GET','/api/datapackage/vehicledata'); if (CkRest_getLastMethodSuccess(rest) <> True) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; if (CkRest_getResponseStatusCode(rest) <> 200) then begin Memo1.Lines.Add('Response Status Code = ' + IntToStr(CkRest_getResponseStatusCode(rest))); Memo1.Lines.Add(jsonResponseStr); Exit; end; json := CkJsonObject_Create(); CkJsonObject_Load(json,jsonResponseStr); CkJsonObject_putEmitCompact(json,False); // Show the JSON response. Memo1.Lines.Add(CkJsonObject__emit(json)); // A sample vehicledata response will be as shown below. // To get a few bits of data from the response: Memo1.Lines.Add('RequestGuid: ' + CkJsonObject__stringOf(json,'RequestGuid')); Memo1.Lines.Add('EngineNumber: ' + CkJsonObject__stringOf(json,'DataItems.EngineNumber')); Memo1.Lines.Add('Vrm: ' + CkJsonObject__stringOf(json,'DataKeys.Vrm')); // { // "RequestGuid": "xxxxxxxx-cc72-4b63-xxxxxxxxxxxx", // "StatusCode": 0, // "StatusMessage": "Success", // "PackageId": "xxxxxxxx-a4bc-4a84-af22-xxxxxxxxxxxx", // "PackageVersion": 1, // "DataKeys": { // "Vrm": "ABCDE" // }, // "DataItems": { // "DriveAxle": "4x2", // "Exported": "False", // "DriverSeatPosition": "RHD", // "EngineNumber": "LN910940728622", // "Class": "Sport", // "ImportedNorthernIreland": "False", // "HistoryPreviousKeeperAcquisitionDate": "2013-01-12", // "RoadFundLicenseSixMonth": "126.50", // "EnginePowerBhp": "262", // "SpecDateRangeFrom": "1987-10-01", // "RegistrationDateUK": "1994-08-03", // "SoundLevelDriveBy": "0", // "RoadFundLicenseTwelveMonth": "235.00", // "RoadFundLicenseBand": "Not available", // "Vrm": "J5YVK", // "TrimCode": "BA", // "Derivative": "S4", // "EngineSizeCc": "2174", // "EngineCylinderCount": "4", // "HistoryLatestV5cIssueDate": "2015-05-12", // "Category": "Car", // "HistoryPreviousKeeperCount": "9", // "ConditionScrapped": "False", // "EngineValveCount": "16", // "WeightUnladen": "0", // "RoadFundLicenseRenewalDate": "2017-04-01", // "Model": "Esprit", // "SpecDateRangeTo": "2003-06-01", // "RoadFundLicenseCurrentStatus": "Tax not due", // "BuildYear": "1994", // "BuildDate": "1994-12-31", // "VinLast4": "1448", // "GearCount": "5", // "SeatCount": "2", // "Make": "Lotus", // "Vin": "SCC082910RHA61448", // "ColourChangeCount": "0", // "DriveType": "Rear Wheel Drive", // "WeightGross": "0", // "EngineCode": "N/A", // "EnginePowerKw": "193", // "SoundLevelEngineSpeed": "0", // "ConditionUnscrapped": "False", // "HistoryPreviousKeeperDisposalDate": "2014-04-26", // "EngineAlignment": "Longitudinal", // "Imported": "False", // "BodyType": "Coupe", // "EnginePosition": "Mid", // "TransmissionType": "Manual", // "WeightFullyLaden": "0", // "SoundLevelStationary": "0", // "FuelType": "Petrol", // "Colour": "YELLOW", // "EngineSizeLitre": "2.2", // "RegistrationDate": "1994-08-03", // "Co2Emissions": "000", // "WeightMaxTowingUnbraked": "0", // "HistoryCurrentKeeperAcquisitionDate": "2015-04-25", // "WeightMaxTowingBraked": "0", // "DoorCount": "2", // "EngineCylinderConfig": "Inline", // "EngineFuelDelivery": "Turbo Injection" // } // } // ----------------------------------------------------------------------------------- // Now get battery data... jsonResponseStr := CkRest__fullRequestNoBody(rest,'GET','/api/datapackage/batterydata'); if (CkRest_getLastMethodSuccess(rest) <> True) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; if (CkRest_getResponseStatusCode(rest) <> 200) then begin Memo1.Lines.Add('Response Status Code = ' + IntToStr(CkRest_getResponseStatusCode(rest))); Memo1.Lines.Add(jsonResponseStr); Exit; end; CkJsonObject_Load(json,jsonResponseStr); // Show the JSON response containing battery data. Memo1.Lines.Add(CkJsonObject__emit(json)); // To get a few pieces of information out of the response... numBatteries := CkJsonObject_SizeOfArray(json,'DataItems.BatteryList'); i := 0; while (i < numBatteries) do begin CkJsonObject_putI(json,i); Memo1.Lines.Add('---- Battery ' + IntToStr(i) + ':'); Memo1.Lines.Add(' Type = ' + CkJsonObject__stringOf(json,'DataItems.BatteryList[I].Type')); Memo1.Lines.Add(' LayoutImage = ' + CkJsonObject__stringOf(json,'DataItems.BatteryList[I].LayoutImage')); Memo1.Lines.Add(' TerminalCode = ' + CkJsonObject__stringOf(json,'DataItems.BatteryList[I].TerminalCode')); i := i + 1; end; // The battery data looks like this: // { // "RequestGuid": "xxxxxxxx-5030-4b3d-a2ed-xxxxxxxxxxxx", // "StatusCode": 0, // "StatusMessage": "Success", // "PackageId": "xxxxxxxx-9ec2-4fd3-9247-xxxxxxxxxxxx", // "PackageVersion": 1, // "DataKeys": { // "Vrm": "ABCDE" // }, // "DataItems": { // "BatteryList": [ // { // "Type": "Primary", // "UkRef": "075", // "LayoutCode": "0", // "LayoutImage": "http://cdn.ukvehicledata.co.uk/battery/layout/0.png", // "TerminalCode": "T1", // "TerminalImage": "http://cdn.ukvehicledata.co.uk/battery/terminal/T1.png", // "HoldDownCode": "B13", // "HoldDownImage": "http://cdn.ukvehicledata.co.uk/battery/holddown/B13.png" // } // ], // "BatteryCount": "1" // } // } CkRest_Dispose(rest); CkJsonObject_Dispose(json); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.