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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Stop Writing Database Migration Scripts: Declarative Schema Sync for Java
  • Searching Kafka Without an Index: Lessons From Building Message Search for Kafdrop
  • ScyllaDB in Enterprise Java: High-Performance NoSQL With Eclipse JNoSQL
  • Member Spotlight: Shai Almong

Trending

  • Microsoft Fabric Throttling: Diagnose Before You Scale
  • Solving Comprehension Debt in AI-Generated Codebases
  • Avoiding AI Debt as a Team
  • YAGNI in the Age of AI Coding

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
DZone Core CORE ·
Apr. 21, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
4.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

  • Stop Writing Database Migration Scripts: Declarative Schema Sync for Java
  • Searching Kafka Without an Index: Lessons From Building Message Search for Kafdrop
  • ScyllaDB in Enterprise Java: High-Performance NoSQL With Eclipse JNoSQL
  • Member Spotlight: Shai Almong

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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