跳到正文
DEV Community· Veriline API·· 1 小時前AI 評分35

自動驗證歐盟 VAT 與 LEI 編號

Validate EU VAT & LEI Numbers Automatically

AI 導讀

Veriline API store 的 Business & Tax-ID Validator 可自動驗證 VAT 編號及查詢法律實體識別碼(LEI),分別透過 EU VIES 和 GLEIF 核實資料。API 會先離線檢查格式及校驗碼,並提供即時查核、LEI 名稱搜尋,以及 70 多個國家的税務識別碼格式支援。VIES 查核未能確定結果時,預設會回傳待驗證狀態,避免因服務中斷而阻止用戶。

正文

Onboarding a European customer usually means two checks: is the VAT number real, and is the legal entity the one you think it is? Doing that by hand in VIES and the GLEIF search UI does not scale. This post shows how to do both with the Business & Tax-ID Validator on the Veriline API store.

The API first checks format and check digits offline. A typo is rejected with HTTP 422 before any upstream call. EU and Northern Ireland (XI) numbers can then be confirmed live against the official EU VIES service, which returns the registered name and address when the member state shares them. Legal Entity Identifiers are resolved through official GLEIF records, by LEI or by name.

Auth and base URL

Subscribe on the product page and send your API.market key as x-api-market-key. The gateway is:

https://prod.api.market/api/v1/veriline/business-tax-id-validator

Use prod.api.market, not api.market, for API traffic (the latter returns HTTP 421). The Basic trial allows 1 request per second; successful 200 responses count, 4xx responses do not.

Every response uses a shared envelope: { success, data, error, meta }. meta.took_ms and meta.request_id are per-call.

Validate a VAT number

GET /v1/validate/vat

Parameter Required Notes
vat yes The number, with or without the country prefix. Aliases number, tin and id are accepted.
country no ISO 3166-1 alpha-2. Required when the number has no prefix.
live no Default true. Set false to skip VIES and stop at the checksum.
strict no Default false. If true, an inconclusive VIES result becomes HTTP 502/503 instead of format_valid_unverified.

IE6388047V is the well-known VIES example number for Google Ireland. A live call through the gateway:

curl -G 'https://prod.api.market/api/v1/veriline/business-tax-id-validator/v1/validate/vat' \
  --data-urlencode 'vat=IE6388047V' \
  --data-urlencode 'live=true' \
  -H 'x-api-market-key: YOUR_API_KEY'
{
  "success": true,
  "data": {
    "input": "IE6388047V",
    "country_code": "IE",
    "country_name": "Ireland",
    "id_type": "VAT no.",
    "vat_number": "IE6388047V",
    "national_number": "6388047V",
    "format_valid": true,
    "checksum": "passed",
    "offline_valid": true,
    "vies_eligible": true,
    "live_check": {
      "performed": true,
      "source": "EU VIES",
      "status": "valid",
      "valid": true,
      "name": "GOOGLE IRELAND LIMITED",
      "address": "3RD FLOOR, GORDON HOUSE, BARROW STREET, DUBLIN 4",
      "consultation_number": null,
      "attempts": 1
    },
    "verdict": "valid"
  }
}

Automate against data.verdict, not only HTTP 200:

verdict Meaning
valid Format, checksum and live VIES all passed. Use live_check.name and live_check.address.
invalid The number failed a check. For a live miss, live_check.valid is false.
format_valid Offline only (live=false, or a country with no free official live registry).
format_valid_unverified Checksum passed, but VIES was down, rate-limited, or inconclusive (live_check.valid is null).

VIES member states are occasionally offline. The API retries once. Unless you pass strict=true, you get HTTP 200 with format_valid_unverified and the VIES status (for example rate_limited or service_unavailable) rather than a hard failure. That is the behaviour you want in a checkout form: accept the format, flag the live check for a retry, and do not block the user on an EU outage.

For a format-only pass — useful in unit tests, or when you are batching IDs and want to reserve VIES for numbers that already checksum — use either live=false or GET /v1/validate/tin (same offline logic, never calls upstream):

curl -G 'https://prod.api.market/api/v1/veriline/business-tax-id-validator/v1/validate/tin' \
  --data-urlencode 'tin=IE6388047V' \
  --data-urlencode 'country=IE' \
  -H 'x-api-market-key: YOUR_API_KEY'

verdict will be format_valid, and live_check.performed will be false.

A bad check digit is HTTP 422, and it does not consume trial units:

curl -G 'https://prod.api.market/api/v1/veriline/business-tax-id-validator/v1/validate/vat' \
  --data-urlencode 'vat=DE811907981' \
  -H 'x-api-market-key: YOUR_API_KEY'
{
  "success": false,
  "data": null,
  "error": {
    "code": "checksum_failed",
    "message": "USt-IdNr. failed its DE check-digit test",
    "details": {
      "input": "DE811907981",
      "country_code": "DE",
      "format_valid": true,
      "checksum": "failed",
      "offline_valid": false,
      "verdict": "invalid"
    }
  }
}

GET /v1/countries lists the supported tax-ID formats (70+ countries, including all 27 EU states, plus the UK, Australia ABN, India GSTIN, Brazil CNPJ and others). Each entry has country_code, id_type, live_vies, checksum and an example.

Look up a Legal Entity Identifier

GET /v1/lookup/lei — provide lei or name. If both are present, lei is used as a direct fetch.

Parameter Notes
lei 20-character ISO 17442 LEI. Check digits are verified before GLEIF is called.
name 2–120 characters. Company-name search.
country Optional ISO alpha-2 legal-address filter, for name search.
limit / page 1–50 (default 10) and 1–100 (default 1).

Apple Inc.'s LEI, live through the gateway:

curl -G 'https://prod.api.market/api/v1/veriline/business-tax-id-validator/v1/lookup/lei' \
  --data-urlencode 'lei=HWUPKR0MPOU8FGXBT394' \
  -H 'x-api-market-key: YOUR_API_KEY'
{
  "success": true,
  "data": {
    "lei": "HWUPKR0MPOU8FGXBT394",
    "legal_name": "Apple Inc.",
    "other_names": [
      { "name": "Apple Computer, Inc.", "type": "PREVIOUS_LEGAL_NAME" }
    ],
    "entity_status": "ACTIVE",
    "jurisdiction": "US-CA",
    "legal_address": {
      "city": "Glendale",
      "region": "US-CA",
      "postal_code": "91203",
      "country": "US"
    },
    "headquarters_address": {
      "lines": ["One Apple Park Way"],
      "city": "Cupertino",
      "region": "US-CA",
      "postal_code": "95014",
      "country": "US"
    },
    "registration": {
      "status": "ISSUED",
      "next_renewal_date": "2027-03-08T17:27:20Z",
      "corroboration_level": "FULLY_CORROBORATED"
    },
    "is_active": true,
    "bic": ["APLEUS66XXX"],
    "conformity_flag": "CONFORMING",
    "source_url": "https://search.gleif.org/#/record/HWUPKR0MPOU8FGXBT394"
  }
}

For a KYB flow, the useful flags are is_active, entity_status, registration.status, registration.next_renewal_date and conformity_flag. other_names catches previous legal names. A wrong checksum is HTTP 422 (invalid_lei_checksum) and never hits GLEIF; an unknown but well-formed LEI is HTTP 404.

Name search returns a page:

curl -G 'https://prod.api.market/api/v1/veriline/business-tax-id-validator/v1/lookup/lei' \
  --data-urlencode 'name=Apple Inc' \
  --data-urlencode 'country=US' \
  --data-urlencode 'limit=3' \
  -H 'x-api-market-key: YOUR_API_KEY'

The body is { total, page, limit, last_page, results }, and each result has the same shape as the direct LEI lookup. In a sample search for Apple Inc in the US, the first of three results was Apple Inc. (HWUPKR0MPOU8FGXBT394) among other similarly named entities. Always confirm the LEI, jurisdiction and headquarters before you treat a search hit as a match.

A simple onboarding sequence

A practical order for a new customer record:

  1. Call GET /v1/validate/vat with live=true (or live=false first if you want to reject typos cheaply, then retry live). Branch on verdict.
  2. If verdict is valid, store live_check.name and live_check.address. If it is format_valid_unverified, accept the number provisionally and retry VIES later.
  3. If you also have an LEI, call GET /v1/lookup/lei?lei=… and compare legal_name / other_names to the VIES name. They will not always match exactly: VIES often returns uppercase, and the registered legal name can differ from a trading name.
  4. If you only have a company name, search GLEIF with name and country, then require a human or a secondary match (jurisdiction, city, LEI) before you write the identifier down.

Pace the two product calls by at least one second on the Basic plan. Both endpoints share the same 1 request/second cap.

A small Node and Python wrapper

const apiKey = process.env.API_MARKET_KEY;
const base =
  "https://prod.api.market/api/v1/veriline/business-tax-id-validator";

async function verilineGet(path, params) {
  const url = new URL(`${base}${path}`);
  for (const [k, v] of Object.entries(params)) url.searchParams.set(k, String(v));
  const res = await fetch(url, { headers: { "x-api-market-key": apiKey } });
  const body = await res.json();
  if (!body.success) {
    const err = new Error(body.error?.message || `HTTP ${res.status}`);
    err.status = res.status;
    err.code = body.error?.code;
    err.details = body.error?.details;
    throw err;
  }
  return body.data;
}

const vat = await verilineGet("/v1/validate/vat", {
  vat: "IE6388047V",
  live: "true",
});
// Basic trial cap is 1 request/second
await new Promise((resolve) => setTimeout(resolve, 1000));
const lei = await verilineGet("/v1/lookup/lei", {
  lei: "HWUPKR0MPOU8FGXBT394",
});
import os
import time
import requests

API_KEY = os.environ["API_MARKET_KEY"]
BASE = "https://prod.api.market/api/v1/veriline/business-tax-id-validator"

def veriline_get(path, **params):
    res = requests.get(
        f"{BASE}{path}",
        params=params,
        headers={"x-api-market-key": API_KEY},
        timeout=10,
    )
    body = res.json()
    if not body.get("success"):
        raise RuntimeError(f"{res.status_code} {body.get('error')}")
    return body["data"]

vat = veriline_get("/v1/validate/vat", vat="IE6388047V", live="true")
time.sleep(1)  # Basic trial cap is 1 request/second
lei = veriline_get("/v1/lookup/lei", lei="HWUPKR0MPOU8FGXBT394")

If you also collect payout accounts, GET /v1/validate/iban does an offline mod-97 / BBAN check for 89 IBAN-registry countries and returns bank_code, branch_code and sepa_member. It does not call a live bank directory.

The official MCP server, @verilineapi/mcp, exposes validate_vat, lookup_lei and validate_iban with the same arguments if you would rather call this from an MCP client than from HTTP.

Docs and pricing live on the Business & Tax-ID Validator page. Questions: verilineapi@proton.me.

來源:DEV Community · dev.to