Home / Use cases / Java

Java

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. 1

    Use java.net.http.HttpClient — no extra HTTP library needed

  2. 2

    Set the Authorization header with your API key from environment

  3. 3

    Deserialize the JSON response with Jackson ObjectMapper

  4. 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:

200 OK (active)valid
{
  "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.

active

VAT number is valid and the business is registered

invalid

VAT number format is wrong or not registered in VIES

service_unavailable

VIES or the national system is temporarily down — retry later

Evaluating EU VAT APIs? Compare TaxID vs Vatstack, Vatlayer, Avalara →

Ready to implement?

Get your free API key and start validating EU VAT numbers today.

Get free API key

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...