EU VAT validation in Ruby / Rails
Validate EU VAT numbers in Ruby or Ruby on Rails using the standard Net::HTTP library. Zero gem dependencies — integrates cleanly with ActiveRecord models and Rails service objects.
Implementation steps
- 1
Use Net::HTTP with use_ssl = true for the HTTPS request
- 2
Set the Authorization header with your API key from ENV
- 3
Parse the JSON response with Ruby's built-in JSON module
- 4
Update your ActiveRecord model with the validation result and company name
Code example
Ruby
require 'net/http'
require 'json'
def validate_vat(country, vat_number)
uri = URI("http://localhost:3000/api/v1/validate/#{country}/#{vat_number}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['Authorization'] = "Bearer #{ENV['TAXID_API_KEY']}"
response = http.request(request)
JSON.parse(response.body)
end
result = validate_vat('DE', 'DE123456789')
if result['valid']
puts "Valid EU business: #{result['company_name']}"
elsif result['status'] == 'service_unavailable'
# VIES is temporarily down — allow through and validate later
puts 'VIES unavailable — retry later'
else
puts 'Invalid VAT number'
endcURL
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...