Syncing Customer VAT IDs from Your ERP: A Validation Pattern
27 Nov 2026

Validate a customer’s VAT ID with a single check when the record is created or the VAT field is edited, re-check the whole base with one bulk job per scheduled run, and put key accounts on monitoring with webhooks. Whatever comes back, write down a status from a small fixed set and never let an error overwrite a verdict you already hold.
vatnode has no ERP connector. This is the generic pattern over REST, and it works whichever system holds the customer master data. If you only need a one-off pass over an existing base, bulk re-validating customer VAT IDs covers the backfill. This post is about the loop that keeps the data right afterwards: what a VIES VAT API integration looks like when the customer master data lives in your ERP.
The pattern in one table
| Lifecycle event | API path | What you write back |
|---|---|---|
| New customer or edited VAT field | GET /v1/vat/{vatId} | status, verifiedAt, source, checkId, consultationNumber, optional company data |
| Scheduled sweep of the whole base | POST /v1/vat/bulk and read the results | status, processedAt, source, checkId, consultationNumber |
| Key accounts you want to hear about | POST /v1/subscriptions plus webhooks | a status change, then a fresh single check for the evidence |
All calls use Authorization: Bearer <key> and run server-side. The VAT validation reference has the full single-check response, and the VAT API overview covers what the product does.
Decide the trigger
On create or edit: single check. The user is waiting, so you want a synchronous answer. Call GET /v1/vat/{vatId} from your backend when the VAT ID is saved. A 200 with valid: true or valid: false is a verdict. Anything that is not 200 is not a verdict, and the form should say ‘could not check right now’ rather than ‘invalid’.
On a schedule: bulk. A nightly or monthly sweep over thousands of customers is a job, not a loop. POST /v1/vat/bulk takes up to 50,000 IDs, returns a jobId straight away, and you poll. Mint one Idempotency-Key per sync run and persist it before the first call, so a retry after a dropped connection returns the same job instead of counting the batch twice. The same key with a different list, including the same IDs in another order, is a 409 IDEMPOTENCY_KEY_CONFLICT, so build the list in a stable order. The submit, poll and retry code is in the bulk submit-and-poll client, and the contract is in the bulk validation reference.
For key accounts: monitoring. POST /v1/subscriptions with { "vatId": "..." } registers one ID per call. vatnode re-validates it daily and tells you when the state changes. Monitoring and webhooks start on the paid plans, with per-plan limits on /pricing; the free plan covers single and bulk checks. You will not put your whole base on monitoring, so it sits next to the periodic sweep rather than replacing it. Details are in the monitoring reference.
Normalise before you sync
Garbage in the VAT field is a common reason a sync looks unreliable. Before the export leaves your ERP:
- Trim and uppercase. Bulk does this for you anyway, but your own duplicate detection should see the same value.
- Expect duplicates. Several customer records can share one VAT ID. Bulk collapses them and bills the position once, so map the results back by VAT ID, not by row number.
- Expect
INVALID_FORMAT. A malformed number answersINVALID_FORMATand is not billed. That is a data problem on your side, and the right status isFORMAT_ERROR, notINVALID.
Build and test the single and bulk paths on a vat_test_ key before touching live data. Monitoring and webhooks don’t accept test keys and need a live one. In test mode every ID must start with XX, nothing is billed and VIES is not called. XX0000001 and XX0000002 are valid, XX0000003 is invalid, XX0000004 fails with VIES_UNAVAILABLE and XX0000005 with VIES_ERROR. See test mode and the test keys post.
A status vocabulary for the master record
A boolean vat_valid column loses information the first time VIES is down. Use a status with five values:
| Status | Meaning |
|---|---|
VIES_VALID | valid: true and source is VIES |
REGISTER_VALID | valid: true and source is a national register code, or a CACHE hit with no earlier VIES_VALID |
INVALID | valid: false in a 200 response, or a bulk position with valid: false |
FORMAT_ERROR | the number failed format validation (INVALID_FORMAT) |
UNCHECKED_RETRY | never checked yet, or the last attempt failed |
The line that matters is between INVALID and everything else: only a 200 with valid: false is invalid. On the single path every failure is a non-200 response with { "error": { "code", "message", "requestId" } }. In a bulk job a failed position has valid: null plus an error.code (a still-pending one has valid: null and no error), and HTTP stays 2xx whatever the positions do. Neither is a verdict about the customer (codes are in the error reference). And INVALID means the number was reported as not valid at that moment, not that the customer isn’t a business: ask them to confirm the number before you change how you invoice them.
Two source values need a decision. A national register code means the answer reflects domestic VAT registration, not a VIES confirmation, which is why it gets its own status. CACHE means the answer is a prior result up to 15 minutes old. The response does not say which upstream produced it, so the mapping below keeps a previous VIES_VALID and otherwise settles for the weaker REGISTER_VALID. A kept VIES_VALID is a statement about the earlier check, not a fresh VIES confirmation. If you want every check fresh from VIES, set a requester VAT once in the dashboard under Account details. The cache is then bypassed and the national fallback is skipped, so an outage comes back as an error rather than a register answer.
export type VatStatus =
| 'VIES_VALID'
| 'REGISTER_VALID'
| 'INVALID'
| 'FORMAT_ERROR'
| 'UNCHECKED_RETRY'
export type Answer = {
valid: boolean | null // null on a failed or still-pending bulk position
source: string | null
errorCode: string | null
}
export function toStatus(a: Answer, previous: VatStatus | null): VatStatus {
if (a.valid === false) return 'INVALID'
if (a.valid === true) {
if (a.source === 'VIES') return 'VIES_VALID'
if (a.source === 'CACHE') return previous === 'VIES_VALID' ? 'VIES_VALID' : 'REGISTER_VALID'
return 'REGISTER_VALID'
}
if (a.errorCode === 'INVALID_FORMAT') return 'FORMAT_ERROR'
// An error is not a verdict: keep what you already know.
return previous ?? 'UNCHECKED_RETRY'
}
The same function serves both paths. For a bulk position pass item.valid, item.source and item.error?.code.
What to write back, per path
The two paths return different fields, so the record you store is different too.
| Field | Single check | Bulk position |
|---|---|---|
verdict (valid) | yes | yes (or null) |
vatId (normalised) | yes | yes |
source | yes | yes |
checkId | yes | yes (null without a verdict, and always in test mode) |
consultationNumber | yes, or null | yes, or null |
| check time | verifiedAt | processedAt |
companyName, companyAddress | yes | no |
If you want name and address on the record, take them from a single check: bulk positions carry no company data.
{
"vat_id": "XX0000001",
"vat_status": "VIES_VALID",
"vat_source": "VIES",
"vat_checked_at": "2026-11-27T09:00:00.000Z",
"vat_check_id": "<checkId from the response>",
"vat_consultation_number": null,
"vat_last_attempt_error": null
}
Some notes on those fields:
consultationNumberappears only when a requester VAT is set once in the dashboard (Account details) and only on aVIESsource. There is no per-call parameter. If it isnull, storenullrather than inventing one. It is a reference to that VIES query, not proof that the customer is registered or that your tax treatment is right.- A register verdict is not a VIES confirmation. If a VIES confirmation matters for how you invoice a cross-border B2B sale, for example not charging VAT on an intra-EU supply of goods, run the check again once VIES answers for that country and keep the result with
source: VIES. - Persist
checkIdyourself. A bulk job and its positions are deleted 30 days after submission (expiresAt), and the checks stay in the dashboard history under theircheckIdfor the retention period in the Privacy Policy. That history is for people:GET /v1/me/checksis session-only and does not work with an API key, so your sync job cannot look acheckIdup later. Your record is the copy that survives. - Keep the last failed attempt in a separate field, like
vat_last_attempt_error. It tells you why a record is stale without touching the verdict.
Errors never overwrite good data
Branch on the HTTP status and error.code, never on the message text:
400 INVALID_FORMAT: setFORMAT_ERRORand send the record to whoever fixes the data.503 VIES_UNAVAILABLE,504 UPSTREAM_TIMEOUT,502 VIES_ERROR: transient. Keep the old status, retry in the next run.403 VIES_ERROR(VAT_BLOCKEDorIP_BLOCKED): VIES blocked the ID or the caller. A retry repeats the block, so keep the old status and have a person look at the record.502 AUDIT_WRITE_FAILED: the check ran but its record could not be stored, so no verdict is returned. It is not counted against your quota and is safe to retry.429 RATE_LIMITED: your monthly quota is used up on a plan without overage, such as the free plan. Stop the run rather than keep calling. In a bulk job it happens mid-job: the remaining positions come backRATE_LIMITEDand the job still finishes. Re-run only those positions after the quota resets or you upgrade.401and422 INVALID_REQUESTER: configuration, not data. Stop the run and alert someone. Nothing in the customer table is wrong.
Quota is spent only on a verdict, so a retry costs a unit only when it finally gets an answer. The bulk client post has the exact accounting.
A single-check wrapper that applies all of this, runnable against the test fixtures with a vat_test_ key (save the toStatus block above as status.mts and this one as sync.mts, then run VATNODE_API_KEY=vat_test_... npx tsx sync.mts; Node 18 or newer):
import { toStatus, type Answer, type VatStatus } from './status.mts'
const BASE = 'https://api.vatnode.dev'
const KEY = process.env.VATNODE_API_KEY
if (!KEY) throw new Error('Set VATNODE_API_KEY')
async function checkOne(vatId: string, previous: VatStatus | null) {
const res = await fetch(`${BASE}/v1/vat/${encodeURIComponent(vatId)}`, {
headers: { Authorization: `Bearer ${KEY}` },
signal: AbortSignal.timeout(15_000),
})
const body = await res.json().catch(() => ({}))
if (res.status === 401 || res.status === 422) {
throw new Error(`Configuration problem: ${body.error?.code}`) // stop the whole run
}
if (res.status === 429) {
throw new Error('Monthly quota used up: stop and resume after the reset')
}
const answer: Answer = res.ok
? { valid: body.valid, source: body.source, errorCode: null }
: { valid: null, source: null, errorCode: body.error?.code ?? `HTTP_${res.status}` }
return {
vatId,
status: toStatus(answer, previous),
...(res.ok && {
checkedAt: body.verifiedAt,
source: body.source,
checkId: body.checkId,
consultationNumber: body.consultationNumber,
}),
lastAttemptError: answer.errorCode,
}
}
for (const id of ['XX0000001', 'XX0000003', 'XX0000004']) {
console.log(await checkOne(id, null))
}
With the fixtures the first call lands on VIES_VALID, the second on INVALID, and the third on UNCHECKED_RETRY with the error recorded: a failed check on a customer with no history stays unchecked instead of becoming a verdict.
Webhooks: mapping events back to ERP records
Monitoring sends VAT_BECAME_VALID, VAT_BECAME_INVALID, COMPANY_NAME_CHANGED, COMPANY_ADDRESS_CHANGED (the last two only while the number is valid) and VIES_UNAVAILABLE. The envelope is { id, version, event, data, timestamp }. Verify the signature before you parse anything: verifying vatnode webhook signatures has the code.
The traps when mapping an event back to a customer:
- Match on
vatId, notcountryCode. Greece isELin the VAT ID prefix andGRin the payload’scountryCode. A join on country code misses it. - Dedupe on the envelope
id. It is stable across retries, so a redelivered event is the same event. - The payload has no
checkIdand noconsultationNumber. AfterVAT_BECAME_INVALIDorVAT_BECAME_VALID, callGET /v1/vat/{vatId}to get fresh evidence for the record. That is a normal check and costs quota. VIES_UNAVAILABLEleaves the state unchanged. Don’t flip anything in the ERP on it.
New webhooks start disabled and become active only after a successful test delivery. If nothing arrives, check that first.
Operational notes
- Give the sync job its own API key. If it is revoked or rotated, only that job is affected. Structuring API keys across teams covers how.
- Minimise what you store. A sole trader’s VAT number, name and address relate to a natural person, so they are personal data under the GDPR. In some countries the number is even built on the person’s national ID, for example in Sweden and Spain (which VAT numbers belong to a person goes through them). Store the VAT ID where the customer record already needs it, and don’t copy it into extra columns, spreadsheets or logs.
- Read coverage from the docs. Which countries are covered, and which have a national register behind VIES, is on the coverage page. Don’t hard-code it into your sync.
- A VAT result is evidence, not a conclusion. It records what VIES or the register reported at the time of the query. Whether a sale is exempt or falls under reverse charge depends on the transaction itself, so for material decisions ask your tax adviser.
Run it
Create a free account to get a vat_test_ key and run the fixtures above. The free plan also includes live single and bulk checks within its monthly quota, so you can point the same job at a sample of real customers before you pick a plan. Monitoring and webhooks are on the paid plans; limits are on /pricing. The bulk validation reference has the request shapes and the VAT API overview has the rest.
FAQ
When should a customer record in my ERP be validated, and how often should the whole base be re-checked?
Validate when a customer is created and whenever the VAT ID field is edited, using a single check, so the user gets an answer before the record is saved. Re-check the whole base on a schedule you choose with one bulk job per run. EU VAT law does not prescribe a fixed re-check interval, though national rules or guidance may expect verification around the time of supply. Beyond that, the cadence is a business decision based on how much a stale status would cost you, for example before each invoice run or once a month. Key accounts can be put on daily monitoring instead.
Which fields from a VAT check should I store on the customer record, and why persist checkId myself?
Store the verdict, the source, the check time (verifiedAt on a single check, processedAt on a bulk position), the checkId and, when present, the consultationNumber. Add companyName and companyAddress only if you take them from single checks. Persist the checkId yourself because bulk jobs and their positions are deleted 30 days after submission, so your own record is the only copy that outlives the job.
What status should I store when VIES or a national registry is unavailable?
Do not store a new verdict. An outage comes back as an error, not as valid: false, so keep the previous status and record only that the last attempt failed. A customer who has never been checked gets UNCHECKED_RETRY. Retry the failed IDs in the next run. Treating an outage as INVALID would block a legitimate customer for a reason that has nothing to do with them.
Is a result from a national register the same as a VIES confirmation?
No. When the source is a national register code instead of VIES, the verdict reflects the number’s domestic VAT registration. It is not a VIES confirmation and it carries no consultation number. If a VIES confirmation matters for how you invoice a cross-border B2B sale, for example not charging VAT on an intra-EU supply of goods, run the check again in VIES first.
Does vatnode have an ERP connector, or do I build the sync myself?
There is no ERP connector. You build the sync yourself over the REST API: export the customer VAT IDs from your ERP, call the single check, bulk or monitoring endpoints, and write the results back with your ERP’s own import or API. The pattern in this post is the same whichever ERP you run.