PHP code example of vecar / autotrader-api-client

1. Go to this page and download the library: Download vecar/autotrader-api-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vecar / autotrader-api-client example snippets


// Create an instance of the client to obtain an access token.
$api = new \Vecar\AutotraderApiClient\Client();
$accessToken = $api->authentication()->getAccessToken('YOUR_KEY', 'YOUR_SECRET');

// once you have your access token you can create client instances like:
$api = new \Vecar\AutotraderApiClient\Client(['access_token' => $accessToken]);

$vehicle = $api->vehicles()->lookup('123456', 'HG17XXX');

/*
 * Will return something similar to the below.
 * 
 * [
 *     "vehicle" => [
 *       "ownershipCondition" => "Used",
 *       "registration" => "HG17XXX",
 *       "vin" => "WMWWG320503CXXXXX",
 *       "make" => "MINI",
 *       "model" => "Convertible",
 *       "generation" => "Convertible (2015 - 2018)",
 *       "derivative" => "1.5 Cooper Convertible 2dr Petrol (s/s) (136 ps)",
 *       "derivativeId" => "5b746c3a24974b8fa1048b0141356a34",
 *       "vehicleType" => "Car",
 *       "trim" => "Cooper",
 *       "bodyType" => "Convertible",
 *       "fuelType" => "Petrol",
 *       "cabType" => null,
 *       "transmissionType" => "Manual",
 *       ...
 *       ],
 *     ],
 *   ]
 *
 * For the full response see:
 * https://developers.autotrader.co.uk/documentation#vehicle-base-information
 */

// For example, to retrieve the MOT & basic vehicle check datasets
// we can do the following:

use Vecar\AutotraderApiClient\Api\Builders\LookupRequestBuilder;

$request = LookupRequestBuilder::create()
    ->setRegistration('EO66XXX')
    ->setFlags([
        VehicleLookupFlags::BASIC_VEHICLE_CHECK, 
        VehicleLookupFlags::VEHICLE_METRICS
    ]);

$vehicle = $api->vehicles()->lookup($request);

/*
 * Will return something similar to the below.
 * 
 * [
 *     "vehicle" => [
 *       "ownershipCondition" => "Used",
 *       "registration" => "EO66XXX",
 *       "vin" => "WMWWG320503CXXXXX",
 *       "make" => "MINI",
 *       "model" => "Convertible",
 *       "generation" => "Convertible (2015 - 2018)",
 *       "derivative" => "1.5 Cooper Convertible 2dr Petrol (s/s) (136 ps)",
 *       "derivativeId" => "5b746c3a24974b8fa1048b0141356a34",
 *       "vehicleType" => "Car",
 *       "trim" => "Cooper",
 *       "bodyType" => "Convertible",
 *       "fuelType" => "Petrol",
 *       "cabType" => null,
 *       "transmissionType" => "Manual",
 *       ...
 * 
 *       "check" => [
 *           "insuranceWriteoffCategory" => null,
 *           "scrapped" => false,
 *           "stolen" => false,
 *           "imported" => false,
 *           "exported" => false,
 *           "previousOwners" => 1,
 *           "keeperChanges" => [
 *               [
 *                 "dateOfLastKeeper" => "2020-07-14",
 *               ],
 *           ],
 *           "v5cs" => [
 *               [
 *                 "issuedDate" => "2017-06-30",
 *               ],
 *           ],
 *       ],
 * 
 *      "motTests" => [
 *           [
 *               "completedDate" => "2020-06-26T10:05:59Z",
 *               "expiryDate" => "2021-06-25",
 *               "testResult" => "Passed",
 *               "odometerValue" => 16330,
 *               "odometerUnit" => "Miles",
 *               "motTestNumber" => "444811158817",
 *               "rfrAndComments" => [],
 *           ],
 *           ...
 *       ],
 *     ],
 *   ]
 *
 * For the full responses see:
 * https://developers.autotrader.co.uk/documentation#vehicle-base-information
 */