How to Validate EU Membership in PHP

Cloudmersive
2 min readApr 19, 2023

--

Even though we (and our users) probably know which countries are part of the EU off the top of our head, our applications require a validation layer to comfortably make the same assertion.

With the free-to-use API provided below in this article, you can easily implement an EU Membership Validation layer into your applications and return a long list of valuable information about each country in question. For example, requesting information on “France” would retrieve the following information:

{
"Successful": true,
"CountryFullName": "France",
"ISOTwoLetterCode": "FR",
"FIPSTwoLetterCode": "FR",
"ThreeLetterCode": "FRA",
"IsEuropeanUnionMember": true,
"Timezones": [
{
"Name": "Romance Standard Time",
"BaseUTCOffset": "01:00:00",
"Now": "2023-04-19T16:34:40.701796"
}
],
"ISOCurrencyCode": "EUR",
"CurrencySymbol": "€",
"CurrencyEnglishName": "Euro",
"Region": "Europe",
"Subregion": "WesternEurope"
}

The boolean response for “IsEuropeanUnionMember” is the most important information here, and we can use any of the remaining data downstream in our workflow as we see fit.

To install the client SDK, we can run the following command:

composer require cloudmersive/cloudmersive_validate_api_client

And to structure our API call, we can copy & paste from the following code examples:

<?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\AddressApi(


new GuzzleHttp\Client(),
$config
);
$input = new \Swagger\Client\Model\ValidateCountryRequest(); // \Swagger\Client\Model\ValidateCountryRequest | Input request

try {
$result = $apiInstance->addressCheckEUMembership($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling AddressApi->addressCheckEUMembership: ', $e->getMessage(), PHP_EOL;
}
?>

To complete our request for free, we’ll need to provide a free-tier API key in the $config line (free API keys provide a limit of 800 API calls per month).

Now it’s easy to check each country’s EU membership in the midst of your application workflow.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet