How to validate a VAT number in PHP

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.

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(),
$input = new \Swagger\Client\Model\VatLookupRequest(); // \Swagger\Client\Model\VatLookupRequest | Input VAT code
try {
$result = $apiInstance->vatVatLookup($input);
} 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?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store