PHP code example of jlecter / checkvin-php-api-client
1. Go to this page and download the library: Download jlecter/checkvin-php-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/ */
jlecter / checkvin-php-api-client example snippets
use CheckVin\Api\Exception\InvalidVinCode;
try {
$response = $provider->getAutoCheckForVinCode('not-a-vin');
} catch (InvalidVinCode $e) {
echo $e->getMessage(); // reason from checkvin/vincode
// $e->getPrevious() is the LengthNotValidException / NotValidLetterException / CheckSumNotValidException
}
use CheckVin\Api\CheckVin;
$checkVin = new CheckVin('your-api-key');
$response = $checkVin->autocheck()->checkReportExists('1FM5K7D85HGB31870');
if ($response->isSuccess()) {
var_dump($response->getData());
} else {
$error = $response->getError();
if ($error->isMalformedBody()) {
// Transport / gateway problem — no API error payload
echo 'Unexpected response, HTTP ' . $error->getHttpCode();
} elseif ($error->getHttpCode() === 422 && $error->getMessage() === 'Пользователь не найден') {
// Invalid API key — the server returns HTTP 422, not 401/403.
// It cannot be distinguished from a validation error by status code alone;
// check getMessage() for the exact string when you need to tell them apart.
echo 'Invalid API key';
} elseif ($error->getHttpCode() === 404) {
echo 'Report not found';
} elseif ($error->getHttpCode() === 429) {
echo 'Rate limit exceeded';
} else {
// 422 validation error, 5xx, etc.
echo $error->getMessage();
// Field-level details if available:
foreach ($error->getErrors() as $field => $messages) {
echo $field . ': ' . (is_array($messages) ? implode(', ', $messages) : $messages);
}
}
}
use CheckVin\Api\Provider\Autocheck\AutocheckDataProvider;
$provider = new AutocheckDataProvider('your-api-key');
$response = $provider->checkReportExists('1FM5K7D85HGB31870');
use CheckVin\Api\Config\Config;
use CheckVin\Api\Http\Client\Client;
use CheckVin\Api\Provider\Autocheck\AutocheckDataProvider;
$config = new Config(
host: 'https://apicheckvin.xyz',
connectTimeoutMs: 1000, // 1 s connect timeout
timeoutMs: 5000, // 5 s total timeout
);
$client = new Client($config);
$provider = new AutocheckDataProvider('your-api-key', $client);
use CheckVin\Api\Exception\RequestFailed;
try {
$response = $provider->checkReportExists('1FM5K7D85HGB31870');
} catch (RequestFailed $e) {
// curl transport error or timeout
echo $e->getMessage(); // "Request failed (errno N): ..."
}
// ["vincode" => ["The vincode must be at least 17 characters."]]
$error->getErrors();
use CheckVin\Api\Http\Client\Psr18Client;
use CheckVin\Api\Provider\Balance\BalanceDataProvider;
use GuzzleHttp\Client as GuzzleClient;
use Nyholm\Psr7\Factory\Psr17Factory;
// Guzzle 7 implements PSR-18 natively.
// GuzzleHttp\Psr7\HttpFactory also works as the request factory
// (verify the class name against your installed guzzlehttp/psr7 version).
$guzzle = new GuzzleClient([
'connect_timeout' => 1, // seconds
'timeout' => 10,
]);
$factory = new Psr17Factory(); // nyholm/psr7 — implements RequestFactoryInterface
$client = new Psr18Client($guzzle, $factory);
$provider = new BalanceDataProvider('your-api-key', $client);
$response = $provider->getBalance();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.