EU VAT validation in Java
Validate EU VAT numbers in Java using the built-in HttpClient (Java 11+) and Jackson for JSON deserialization. Works with Spring Boot, Quarkus, Micronaut, or any Java 11+ application.
Implementation steps
- 1
Use java.net.http.HttpClient — no extra HTTP library needed
- 2
Set the Authorization header with your API key from environment
- 3
Deserialize the JSON response with Jackson ObjectMapper
- 4
Return B2B validation status to your billing or checkout logic
Code example
Java 11+
import java.net.URI;
import java.net.http.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
// Requires Java 11+ and jackson-databind
public class VATValidator {
static final HttpClient client = HttpClient.newHttpClient();
static final ObjectMapper mapper = new ObjectMapper();
@SuppressWarnings("unchecked")
public static Map<String, Object> validateVAT(
String country, String vatNumber) throws Exception {
var request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:3000/api/v1/validate/" + country + "/" + vatNumber))
.header("Authorization", "Bearer " + System.getenv("TAXID_API_KEY"))
.GET()
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
return mapper.readValue(response.body(), Map.class);
}
public static void main(String[] args) throws Exception {
var result = validateVAT("DE", "DE123456789");
if (Boolean.TRUE.equals(result.get("valid"))) {
System.out.println("Valid EU business: " + result.get("company_name"));
} else if ("service_unavailable".equals(result.get("status"))) {
System.out.println("VIES unavailable — retry later");
} else {
System.out.println("Invalid VAT number");
}
}
}cURL
curl "http://localhost:3000/api/v1/validate/DE/DE123456789" \
-H "Authorization: Bearer $TAXID_API_KEY"
# {
# "valid": true,
# "status": "active",
# "company_name": "Example GmbH",
# "company_address": "Musterstraße 1, 10115 Berlin",
# "cached": false
# }API response
The TaxID API returns a consistent JSON response for every validation request:
{
"valid": true,
"status": "active",
"country_code": "DE",
"vat_number": "123456789",
"company_name": "Example GmbH",
"company_address": "Musterstraße 1, 10115 Berlin",
"request_date": "2026-05-10T00:00:00.000Z",
"cached": false,
"request_id": "req_01j..."
}Error handling
The API uses a consistent Stripe-style error format. Always handle service_unavailable separately — VIES has occasional downtime and you should not reject valid customers during outages.
activeVAT number is valid and the business is registered
invalidVAT number format is wrong or not registered in VIES
service_unavailableVIES or the national system is temporarily down — retry later
Evaluating EU VAT APIs? Compare TaxID vs Vatstack, Vatlayer, Avalara →
Related use cases
Validate EU VAT numbers in Stripe Checkout
Add EU VAT validation to your Stripe checkout flow. Verify customer VAT numbers server-side before a...
UK VAT validation in Shopify B2B
Validate UK VAT numbers for B2B customers in Shopify. Required under UK Making Tax Digital rules for...
WooCommerce Spain NIF/CIF validation
Validate Spanish NIF and CIF numbers in WooCommerce checkout. Automatically apply B2B tax exemptions...