Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[ukvehicledata] UK Vehicle Data PHP Curl Example
<?php
$curl = curl_init();
$ApiKey = "<APIKEY>";
$postedcarreg = '<CARREG>';
$carreg = $postedcarreg;
$datatype = "VehicleData";
$url = "https://uk1.ukvehicledata.co.uk/api/datapackage/%s?v=2&api_nullitems=1&key_vrm=%s&auth_apikey=%s";
$url = sprintf($url, $datatype , $carreg, $ApiKey); // Syntax: sprintf($url, "PackageName", "VRM", ApiKey);
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET"
));
$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
if ($error) {
echo "cURL Error: " . $error;
} else {
$data = json_decode($response, true);
print_r($data);
$cardata = array(
"all" => $data,
"response" => $data[Response][StatusCode],
"reg" => $data[Response][DataItems][VehicleRegistration][Vrm],
"make" => $data[Response][DataItems][ClassificationDetails][Dvla][Make],
"model" => $data[Response][DataItems][ClassificationDetails][Dvla][Model],
"prodyear" => $data[Response][DataItems][VehicleRegistration][YearOfManufacture],
"cc" => $data[Response][DataItems][VehicleRegistration][EngineCapacity],
"cylinders" => $data[Response][DataItems][TechnicalDetails][General][Engine][NumberOfCylinders],
"valves" => $data[Response][DataItems][TechnicalDetails][General][Engine][ValvesPerCylinder],
"fueltype" => $data[Response][DataItems][VehicleRegistration][FuelType],
"type" => $data[Response][DataItems][SmmtDetails][BodyStyle],
"transmission" => $data[Response][DataItems][SmmtDetails][Transmission],
"enumber" => $data[Response][DataItems][VehicleRegistration][EngineNumber],
"ecode" => $data[Response][DataItems][TechnicalDetails][General][Engine][Code][CodeList][0][EngineCode]
);
echo json_encode($cardata);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment