EU VAT validation in Go
Validate EU VAT numbers in Go using the standard net/http package. No external dependencies required — works with any Go 1.18+ project, from simple CLIs to high-throughput microservices.
Implementation steps
- 1
Import net/http and encoding/json from the standard library
- 2
Build a GET request with the Authorization header
- 3
Decode the JSON response into map[string]any or a typed struct
- 4
Handle valid, invalid, and service_unavailable cases
Code example
Go
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
func validateVAT(country, vatNumber string) (map[string]any, error) {
url := fmt.Sprintf("http://localhost:3000/api/v1/validate/%s/%s", country, vatNumber)
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("Authorization", "Bearer "+os.Getenv("TAXID_API_KEY"))
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var result map[string]any
json.NewDecoder(resp.Body).Decode(&result)
return result, nil
}
func main() {
result, _ := validateVAT("DE", "DE123456789")
if result["valid"] == true {
fmt.Println("Valid EU business:", result["company_name"])
} else if result["status"] == "service_unavailable" {
fmt.Println("VIES unavailable — retry later")
} else {
fmt.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...