# CNPJ Validator & Formatter — Bulk Check (Free) (`gangary/cnpj-validator`) Actor

Validate and format Brazilian CNPJs in bulk, for free: official check-digit verification, 00.000.000/0000-00 formatting, headquarters vs branch detection, duplicate flagging and a per-row reason for every invalid entry. Validar CNPJ em lote, gratis.

- **URL**: https://apify.com/gangary/cnpj-validator.md
- **Developed by:** [Gangary](https://apify.com/gangary) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-usage

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## CNPJ Validator & Formatter — Bulk Check (Free)

Paste a list of CNPJs (Brazilian company tax IDs) — get back every one **validated with the official check-digit algorithm**, formatted, classified as headquarters or branch, with duplicates flagged and a clear reason for every invalid entry. **Completely free, no charges, no login, no API key.**

![Cover](https://empresas-por-cnae.vercel.app/covers/cnpj-validator.png)

Em português: *validar CNPJ em lote, verificar dígito verificador, formatar CNPJ, limpar planilha de CNPJs — grátis*.

Perfect for cleaning a spreadsheet **before** paying for registry lookups: run your list here first, then send only the valid, deduplicated CNPJs to [CNPJ Lookup](https://apify.com/gangary/cnpj-lookup).

### Input example

```json
{
  "cnpjs": ["00.000.000/0001-91", "11222333000181", "11111111111111", "123"]
}
```

Formatted or digits-only, both work. Garbage rows (wrong type, empty, too short) never crash the run — they come back classified.

### Output example

One row per input item, in the same order (spreadsheet in, spreadsheet out):

```json
{
  "input": "00.000.000/0001-91",
  "cnpj": "00000000000191",
  "cnpj_formatado": "00.000.000/0001-91",
  "valid": true,
  "reason": "ok",
  "matriz": true,
  "raiz": "00000000",
  "is_duplicate": false
}
```

### Output fields

| Field | Description |
|---|---|
| `valid` | Passed the official check-digit verification (módulo 11). |
| `reason` | Why it failed: `not_14_digits`, `repeated_digits` or `bad_check_digit` — or `ok`. |
| `cnpj` / `cnpj_formatado` | Clean 14 digits and the `00.000.000/0000-00` display form. |
| `matriz` | `true` = headquarters (order `0001`), `false` = branch (filial). |
| `raiz` | First 8 digits — shared by all branches of the same company. |
| `is_duplicate` | Another row in your list normalized to the same CNPJ (different formatting, same company). |

A run summary (`total`, `valid`, `invalid`, `duplicates`) is saved as the run's OUTPUT.

### Use cases

- **Clean a CRM export or purchased list** before enrichment — drop typos and duplicates for free
- **Validate user-supplied CNPJs** in onboarding/checkout flows via API
- **Split matriz vs filial** in a supplier or customer base using `matriz` and `raiz`
- **Pre-flight for paid lookups** — validate here (free), then fetch full registry data only for the valid ones

### Pricing

**Free.** No pay-per-event charges — you only cover Apify's standard compute usage, which for this Actor is negligible (it's pure computation, no network calls).

### Is this compliant?

Yes — the Actor performs a mathematical validation (the public check-digit algorithm defined by Receita Federal). It sends no network requests and collects no data.

### Need more than validation?

- **[Brazilian Companies Finder (CNPJ Discovery)](https://apify.com/gangary/cnpj-discovery)** — don't have a list yet? Search 27.8M active Brazilian companies by CNAE activity + state, straight from the official registry index.
- **[CNPJ Lookup — Brazilian Company Registry Data](https://apify.com/gangary/cnpj-lookup)** — full official record per CNPJ: legal name, status, address, partners, capital, phone and email when on file.
- **[Lead Enricher & ICP Scorer](https://apify.com/gangary/lead-enricher-icp)** — verify, dedupe and score any lead list 0–100 against your ideal customer profile.
- **[B2B Leads Brazil — Find, Enrich & Score in One Run](https://apify.com/gangary/b2b-leads-brazil)** — skip the assembly: it discovers Brazilian companies by activity + state, pulls their contact data and scores every lead 0–100 in a single run, sorted best-first.

**Full pipeline:** validate here (free) → Discovery finds more → Lookup pulls the data → Enricher scores what's worth contacting. **Want all of it in one step?** [B2B Leads Brazil](https://apify.com/gangary/b2b-leads-brazil) runs the whole funnel and returns the finished list.

# Actor input Schema

## `cnpjs` (type: `array`):

Lista de CNPJs pra validar — com ou sem pontuacao, em qualquer ordem. Linhas invalidas nao quebram o run: cada uma volta com o motivo (not\_14\_digits, repeated\_digits, bad\_check\_digit).

## Actor input object example

```json
{
  "cnpjs": [
    "00.000.000/0001-91",
    "11222333000181",
    "11111111111111"
  ]
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "cnpjs": [
        "00.000.000/0001-91",
        "11222333000181",
        "11111111111111"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("gangary/cnpj-validator").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "cnpjs": [
        "00.000.000/0001-91",
        "11222333000181",
        "11111111111111",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("gangary/cnpj-validator").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "cnpjs": [
    "00.000.000/0001-91",
    "11222333000181",
    "11111111111111"
  ]
}' |
apify call gangary/cnpj-validator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=gangary/cnpj-validator",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/3Dcn52hSbrVBrhVAp/builds/QasWvCIjRhMgoooGA/openapi.json
