How to validate a VAT number in PHP
1 min readAug 1, 2019
Today we will demonstrate how easy it is to validate VAT numbers using Cloudmersive’s API. Let us begin.
Add a reference for the Validate API Client in your library with the following code.
"require": {
"cloudmersive/cloudmersive_validate_api_client": "^1.4",
}
The only thing left to do is call our desired function, vatVatLookup.
<?php
require_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');$apiInstance = new Swagger\Client\Api\VatApi(
new GuzzleHttp\Client(),
$config
);
$input = new \Swagger\Client\Model\VatLookupRequest(); // \Swagger\Client\Model\VatLookupRequest | Input VAT codetry {
$result = $apiInstance->vatVatLookup($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling VatApi->vatVatLookup: ', $e->getMessage(), PHP_EOL;
}
?>
The function will return several pieces of pertinent information, including the VAT number, whether it is in fact valid, as well as the company’s name, country, and address.
Pretty easy, huh?