EU VAT validation in .NET / C#
Validate EU VAT numbers in .NET 6+ and C# using HttpClient and System.Text.Json. Includes async/await pattern, strongly-typed response record, and IHttpClientFactory-ready setup.
Implementation steps
- 1
Register HttpClient via IHttpClientFactory in your DI container
- 2
Set the Authorization header with your API key from IConfiguration
- 3
Deserialize the response with System.Text.Json into a C# record type
- 4
Return the VATResult to your controller or application service
Code example
C# / .NET
using System.Net.Http.Headers;
using System.Text.Json;
using System.Text.Json.Serialization;
public record VATResult(
[property: JsonPropertyName("valid")] bool Valid,
[property: JsonPropertyName("status")] string Status,
[property: JsonPropertyName("company_name")] string? CompanyName,
[property: JsonPropertyName("company_address")] string? CompanyAddress
);
// In your service — register HttpClient via IHttpClientFactory in prod
using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer",
Environment.GetEnvironmentVariable("TAXID_API_KEY"));
var url = $"http://localhost:3000/api/v1/validate/DE/DE123456789";
var json = await http.GetStringAsync(url);
var result = JsonSerializer.Deserialize<VATResult>(json)!;
if (result.Valid)
Console.WriteLine($"Valid EU business: {result.CompanyName}");
else if (result.Status == "service_unavailable")
Console.WriteLine("VIES unavailable — retry later");
else
Console.WriteLine("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...