DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Getting Started With Agentic Workflows in Java and Quarkus
  • Building AI-Powered Java Applications With Jakarta EE and LangChain4j
  • Alternative Structured Concurrency
  • Jakarta EE 12: Entering the Data Age of Enterprise Java

Trending

  • AI Paradigm Shift: Analytics Without SQL
  • Contract-First Integration: Building Scalable Systems With Flyway, OpenAPI, and Kafka
  • Stop Running Two Data Systems for One Agent Query
  • Data Contracts as the "Circuit Breaker" for Model Reliability
  1. DZone
  2. Coding
  3. Java
  4. How to Validate a VAT Number in Java

How to Validate a VAT Number in Java

Determine if a VAT Identification Number is valid by using an API in Java. If valid, business contact information will be retrieved as well.

By 
Brian O'Neill user avatar
Brian O'Neill
DZone Core CORE ·
Apr. 21, 21 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
4.5K Views

Join the DZone community and get the full member experience.

Join For Free

Due to advances in technology, international trade and business have been steadily climbing over the past couple decades. Increased online interactions have done their part to make the world smaller and trade prospects wider, and while the pandemic hit the global trading business hard last year, the World Trade Organization is projecting a boost of 8.0% in 2021.

In order to position your company for successful international business travel and transactions in the upcoming year, Value-Added Tax (VAT) regulations must be considered. The European Union requires businesses to be registered with a VAT identification number on the VAT Information Exchange System; if the business is not registered, then they are not eligible to trade within the EU. To internally validate VAT registration, the following API will allow your systems to parse and verify input VAT numbers and return contact information for the corresponding business. Each VAT number should begin with the two-letter ISO country code; possible country codes include Austria (AT), Belgium (BE), Bulgaria (BG), Cyprus (CY), Czech Republic (CZ), Germany (DE), Denmark (DK), Estonia (EE), Greece (EL), Spain (ES), Finland (FI), France (FR), United Kingdom (GB), Croatia (HR), Hungary (HU), Ireland (IE), Italy (IT), Lithuania (LT), Luxembourg (LU), Latvia (LV), Malta (MT), The Netherlands (NL), Poland (PL), Portugal (PT), Romania (RO), Sweden (SE), Slovenia (SI), and Slovakia (SK).

To begin the process, we will install the Maven SDK by adding a reference to the repository in pom.xml:

XML
x
 
1
<repositories>
2
    <repository>
3
        <id>jitpack.io</id>
4
        <url>https://jitpack.io</url>
5
    </repository>
6
</repositories>

Then, we will add a reference to the dependency:

XML
xxxxxxxxxx
1
 
1
<dependencies>
2
<dependency>
3
    <groupId>com.github.Cloudmersive</groupId>
4
    <artifactId>Cloudmersive.APIClient.Java</artifactId>
5
    <version>v3.90</version>
6
</dependency>
7
</dependencies>

With the installation complete, we’re ready to move on to adding the imports to the top of our controller and calling the validation function with the following code:

Java
 




x


 
1
// Import classes:
2
//import com.cloudmersive.client.invoker.ApiClient;
3
//import com.cloudmersive.client.invoker.ApiException;
4
//import com.cloudmersive.client.invoker.Configuration;
5
//import com.cloudmersive.client.invoker.auth.*;
6
//import com.cloudmersive.client.VatApi;
7

          
8
ApiClient defaultClient = Configuration.getDefaultApiClient();
9

          
10
// Configure API key authorization: Apikey
11
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
12
Apikey.setApiKey("YOUR API KEY");
13
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
14
//Apikey.setApiKeyPrefix("Token");
15

          
16
VatApi apiInstance = new VatApi();
17
VatLookupRequest input = new VatLookupRequest(); // VatLookupRequest | Input VAT code
18
try {
19
    VatLookupResponse result = apiInstance.vatVatLookup(input);
20
    System.out.println(result);
21
} catch (ApiException e) {
22
    System.err.println("Exception when calling VatApi#vatVatLookup");
23
    e.printStackTrace();
24
}


To ensure the operations run smoothly, you will need to include the following parameters:

  • VAT Code - the VAT code you wish to perform the validation function on
  • API Key - your personal API key; this can be retrieved by registering for a free account on the Cloudmersive website.

The output for this simple process will indicate the validity of the VAT number, and as promised, will also deliver business contact information for the valid VAT numbers including the business name, address, and the building in which it’s located. This will set you and your company up for success as you pursue new international business opportunities. 

Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Getting Started With Agentic Workflows in Java and Quarkus
  • Building AI-Powered Java Applications With Jakarta EE and LangChain4j
  • Alternative Structured Concurrency
  • Jakarta EE 12: Entering the Data Age of Enterprise Java

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook