PHP Quickstart Guide
Get started with CarsXE's PHP SDK to integrate comprehensive vehicle data into your PHP applications.
The CarsXE PHP SDK provides a simple and powerful way to integrate vehicle data into your PHP applications. This guide will help you get started quickly.
For more information, see the package on Packagist.
Installation
Install the CarsXE PHP package using Composer:
composer require carsxe/carsxe
Setup
First, require the autoloader and initialize the CarsXE client:
app.php
<?php
require_once 'vendor/autoload.php';
use CarsxeDeveloper\Carsxe\Carsxe;
// Initialize the client
$API_KEY = 'YOUR_API_KEY_HERE';
$carsxe = new Carsxe($API_KEY);
Basic Usage
VIN Specifications
app.php
<?php
$vin = 'WBAFR7C57CC811956';
try {
$vehicle = $carsxe->specs(['vin' => $vin]);
echo $vehicle['input']['vin'];
} catch (Exception $error) {
echo "Error: " . $error->getMessage();
}
International VIN Decoder
app.php
<?php
try {
$intvin = $carsxe->intVinDecoder([
'vin' => 'WF0MXXGBWM8R43240'
]);
echo json_encode($intvin, JSON_PRETTY_PRINT);
} catch (Exception $error) {
echo "Error: " . $error->getMessage();
}
Market Value
app.php
<?php
try {
$marketvalue = $carsxe->marketValue([
'vin' => 'WBAFR7C57CC811956'
]);
echo json_encode($marketvalue, JSON_PRETTY_PRINT);
} catch (Exception $error) {
echo "Error: " . $error->getMessage();
}
Vehicle History
app.php
<?php
try {
$history = $carsxe->history([
'vin' => 'WBAFR7C57CC811956'
]);
echo json_encode($history, JSON_PRETTY_PRINT);
} catch (Exception $error) {
echo "Error: " . $error->getMessage();
}
License Plate Decoder
app.php
<?php
try {
$decoded_plate = $carsxe->plateDecoder([
'plate' => '7XER187',
'state' => 'CA',
'country' => 'US'
]);
echo json_encode($decoded_plate, JSON_PRETTY_PRINT);
} catch (Exception $error) {
echo "Error: " . $error->getMessage();
}
Vehicle Images
app.php
<?php
try {
$images = $carsxe->images([
'make' => 'BMW',
'model' => 'X5',
'year' => '2019'
]);
echo json_encode($images, JSON_PRETTY_PRINT);
} catch (Exception $error) {
echo "Error: " . $error->getMessage();
}
Vehicle Recalls
app.php
<?php
try {
$recalls = $carsxe->recalls([
'vin' => '1C4JJXR64PW696340'
]);
echo json_encode($recalls, JSON_PRETTY_PRINT);
} catch (Exception $error) {
echo "Error: " . $error->getMessage();
}
Plate Image Recognition
app.php
<?php
try {
$plateimg = $carsxe->plateImageRecognition([
'upload_url' => 'https://api.carsxe.com/img/apis/plate_recognition.JPG'
]);
echo json_encode($plateimg, JSON_PRETTY_PRINT);
} catch (Exception $error) {
echo "Error: " . $error->getMessage();
}
VIN OCR from Image
app.php
<?php
try {
$vinocr = $carsxe->vinOcr([
'upload_url' => 'https://api.carsxe.com/img/apis/plate_recognition.JPG'
]);
echo json_encode($vinocr, JSON_PRETTY_PRINT);
} catch (Exception $error) {
echo "Error: " . $error->getMessage();
}
Year-Make-Model Search
app.php
<?php
try {
$yymm = $carsxe->yearMakeModel([
'year' => '2012',
'make' => 'BMW',
'model' => '5 Series'
]);
echo json_encode($yymm, JSON_PRETTY_PRINT);
} catch (Exception $error) {
echo "Error: " . $error->getMessage();
}
OBD Code Decoder
app.php
<?php
try {
$obdcode = $carsxe->obdCodesDecoder([
'code' => 'P0115'
]);
echo json_encode($obdcode, JSON_PRETTY_PRINT);
} catch (Exception $error) {
echo "Error: " . $error->getMessage();
}
Error Handling
The SDK provides comprehensive error handling:
error_handling.php
<?php
use CarsXE\Exceptions\CarsXEException;
use CarsXE\Exceptions\CarsXEApiException;
try {
$result = $carsxe->specs([
'vin' => 'INVALID_VIN'
]);
} catch (CarsXEApiException $e) {
switch ($e->getStatusCode()) {
case 400:
echo "Invalid VIN format";
break;
case 401:
echo "Invalid API key";
break;
case 429:
echo "Rate limit exceeded";
break;
default:
echo "API error: " . $e->getMessage();
}
} catch (CarsXEException $e) {
echo "Client error: " . $e->getMessage();
} catch (Exception $e) {
echo "Unexpected error: " . $e->getMessage();
}
Environment Variables
Store your API key securely using environment variables:
.env
# .env file
CARSXE_API_KEY=your_api_key_here
app.php
<?php
// Using vlucas/phpdotenv
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$carsxe = new CarsXE([
'api_key' => $_ENV['CARSXE_API_KEY']
]);
Available Endpoints
Method | Description |
---|---|
$carsxe->specs(['vin' => $vin]) | Decode VIN & get full vehicle specifications |
$carsxe->intVinDecoder(['vin' => $vin]) | Decode VIN with worldwide support |
$carsxe->plateDecoder(['plate' => $plate, 'state' => $state, 'country' => $country]) | Decode license plate info |
$carsxe->marketValue(['vin' => $vin]) | Estimate vehicle market value based on VIN |
$carsxe->history(['vin' => $vin]) | Retrieve vehicle history |
$carsxe->images(['make' => $make, 'model' => $model, 'year' => $year]) | Fetch images by make, model, year, trim |
$carsxe->recalls(['vin' => $vin]) | Get safety recall data for a VIN |
$carsxe->plateImageRecognition(['upload_url' => $url]) | Read & decode plates from images |
$carsxe->vinOcr(['upload_url' => $url]) | Extract VINs from images using OCR |
$carsxe->yearMakeModel(['year' => $year, 'make' => $make, 'model' => $model]) | Query vehicle by year, make, model and trim |
$carsxe->obdCodesDecoder(['code' => $code]) | Decode OBD error/diagnostic codes |
Start building powerful automotive applications with CarsXE's PHP SDK!