export type GetApiApiVatValidateArgs = {api_key: string, vat_number: string, country?: string | undefined, requester_vat_number?: string | undefined, format?: ('json' | 'xml' | 'csv' | 'tsv') | undefined, callback?: string | undefined}; export type GetApiApiVatValidateOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Validate a VAT number against the official registry (Pro subscription required). EU member states and Northern Ireland (XI) are checked against the European Commission's VIES service, Norwegian (NO) numbers against the Brønnøysund Register Centre (data.brreg.no, NLOD licence) and Swiss (CHE) numbers against the Swiss UID register. UK (GB) validation against HMRC is coming soon: until it is enabled, GB numbers are format-checked and then answered `valid: null, status: unavailable` with `upstream_error: SOURCE_NOT_CONFIGURED` (HTTP 503, not counted against your daily quota) — see /api/vat/validate/status. Numbers are format- and checksum-checked first, so an obviously invalid number returns `status: invalid_format` without an upstream lookup. Results are cached (valid answers 24h, invalid 1h). If the registry is unavailable, the response is `valid: null, status: unavailable` (HTTP 503) — never "invalid" — or, when a previous definitive answer exists, that answer flagged `stale: true` (HTTP 200). The response also carries the country's standard VAT rate from the /api/vat/rates dataset. Norwegian answers include an `attribution` string required by the NLOD licence ("Contains data under the Norwegian licence for Open Government data (NLOD) distributed by the Brønnøysund Register Centre"); keep it when you redistribute that data. `attribution` is null for other countries. * * GET /api/vat/validate */ export const getApiApiVatValidate = async (args: GetApiApiVatValidateArgs, options: GetApiApiVatValidateOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "valid") if (args.api_key != null) query.append("api_key", String(args.api_key)) if (args.vat_number != null) query.append("vat_number", String(args.vat_number)) if (args.country != null) query.append("country", String(args.country)) if (args.requester_vat_number != null) query.append("requester_vat_number", String(args.requester_vat_number)) if (args.format != null) query.append("format", String(args.format)) if (args.callback != null) query.append("callback", String(args.callback)) const url = `${baseUrl.replace(/\/+$/, '')}/api/vat/validate${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };