Tools API Blog
Sign in Create account

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, and Content-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)

OptionDefaultWhat it does
tax_id-Required. The NIF, NIE or CIF to validate, with or without spaces/dashes.

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).