Validate NIF, NIE or CIF
Validate NIF/NIE/CIF is an API that checks the check letter or digit of a Spanish tax ID, before you store it on an invoice or a form. Scope: Spain only, unlike a VAT number from any EU country.
How it works
You send the ID (with or without spaces/dashes) and it detects whether it's a NIF (8 digits + letter), a NIE (X/Y/Z + 7 digits + letter) or a CIF (letter + 7 digits + a check digit or letter), and mathematically checks whether the check character matches. It doesn't query Spain's tax agency or any registry: just the number's own arithmetic.
An invalid ID isn't a request error: the response is 200 with "valid": false, same as when it's valid.
How the DNI and NIE check letter is calculated
You can check it by hand: divide the number by 23 and keep the remainder (0 to 22). That remainder is the position of the letter in this list: TRWAGMYFPDXBNJZSQVHLCKE (T is 0, R is 1, and so on up to E, which is 22).
- DNI: 12345678 divided by 23 leaves a remainder of 14, which is Z. That's why 12345678Z is a valid NIF.
- NIE: replace the first letter with a number (X = 0, Y = 1, Z = 2) and do the same sum. X1234567 becomes 01234567, the remainder is 19 and the letter is L: X1234567L.
A matching letter only tells you the number is written correctly, not that it exists or who it belongs to. For that you have to ask Spain's tax agency.
Honest note about the CIF
Which CIF organization letters require a digit check and which require a letter varies by source. Rather than risk an incorrect rule, this tool accepts either mathematically valid form of the check character. It checks the checksum, not whether the company is actually registered.
All you need
- Your API key. Create it in your dashboard with "+ Create key". It's shown only once, so copy and save it.
- In your automation platform, an "HTTP Request" step (n8n, Make, Zapier, Pipedream… all have one).
How to use it in n8n (step by step)
In the HTTP Request node:
- Method:
POST - URL:
https://api.cofferdock.com/validate-tax-id - Send Headers: on → add two:
x-api-key= your key, andContent-Type=application/json - Send Body: on → Body Content Type: JSON →
{ "tax_id": "12345678Z" }
In Make (HTTP → Make a request module): same method and URL, Body type: Raw, Content type: JSON, with the same body.
Options (inside the JSON)
| Option | Default | What it does |
|---|---|---|
tax_id | - | Required. The NIF, NIE or CIF to validate, with or without spaces/dashes. |
API overview
- Endpoint:
POST https://api.cofferdock.com/validate-tax-id - Auth: header
x-api-key: YOUR_KEY. - Input:
application/jsonONLY. - Algorithm: NIF/NIE check letter (modulo 23) and CIF checksum, pure JS (no external dependency or third-party service, no query to Spain's tax agency).
- Limits: 30 requests/min per IP. 1 call = 1 credit, valid or not.
Options
| Option | Default | Description |
|---|---|---|
tax_id | - | Required. Non-empty string, up to 20 characters (400 otherwise). |
Examples
curl:
curl -X POST "https://api.cofferdock.com/validate-tax-id" \
-H "x-api-key: YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"tax_id":"12345678Z"}'
JavaScript (Node 18+):
const r = await fetch('https://api.cofferdock.com/validate-tax-id', {
method: 'POST',
headers: { 'x-api-key': 'YOUR_KEY', 'Content-Type': 'application/json' },
body: JSON.stringify({ tax_id: '12345678Z' }),
});
const { valid, type } = await r.json();
Response
{ "success": true, "valid": true, "type": "nif", "formatted": "12345678Z",
"meta": { "used": 12, "remaining": 488 } }
What you get back
valid (true/false), type (nif/nie/cif, or null if it matches no Spanish format) and formatted (the ID uppercased with no spaces).