# Brazilian Companies Finder — by CNAE & State (CNPJ Discovery) (`gangary/cnpj-discovery`) Actor

Find every active Brazilian company matching a CNAE activity code and state in seconds — no scraping, powered by an official Receita Federal data index. Filter further by city and company size. Get CNPJ, legal name, trade name, activity, city, size and opening date.

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

## Pricing

from $2.00 / 1,000 per company founds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js/docs.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python/docs.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/integrations/mcp.md).

If your project is in a different language, use 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

## Brazilian Companies Finder — by CNAE & State (CNPJ Discovery)

Pick an economic activity (CNAE) and a state — get back **every active Brazilian company that matches**: CNPJ, legal name, trade name, city, size and opening date. Search across **27.8 million active companies** indexed from the official Federal Revenue (Receita Federal) open dataset. No scraping, no login, no API key.

![Cover](https://empresas-por-cnae.vercel.app/covers/cnpj-discovery.png)

Also searchable in Portuguese: *lista de empresas por CNAE e estado, empresas ativas por segmento, prospecção B2B com dados da Receita Federal*.

**This is the discovery layer**: it finds the companies. Pair it with [CNPJ Lookup](https://apify.com/gangary/cnpj-lookup) (full registry data per company) and the [Lead Enricher & ICP Scorer](https://apify.com/gangary/lead-enricher-icp) (verify and score before outreach) for a complete prospecting pipeline.

### Input example

Dental clinics in São Paulo and Minas Gerais, up to 500 results:

```json
{
  "cnae": "8630-5/04",
  "ufs": ["SP", "MG"],
  "limit": 500
}
````

- `cnae` accepts the full code (`8630-5/04`), digits only (`8630504`) or a **prefix** (`8630` = every outpatient activity, `86` = all of healthcare).
- `municipio` narrows to one city (accent-insensitive: `"Sao Paulo"` works).
- `porte` filters by declared company size (`MEI/micro`, `small`, `other`).
- `offset` + `limit` paginate a big segment across cheap runs.

### Output example

```json
{
  "cnpj": "12345678000195",
  "cnpj_formatado": "12.345.678/0001-95",
  "razao_social": "CLINICA ODONTOLOGICA EXEMPLO LTDA",
  "nome_fantasia": "Sorriso Exemplo",
  "cnae_principal": "8630504",
  "cnae_formatado": "8630-5/04",
  "municipio": "SAO PAULO",
  "uf": "SP",
  "porte": "MICRO EMPRESA",
  "data_abertura": "2019-03-14",
  "tem_email": true,
  "tem_telefone": true
}
```

### Output fields

| Field | Description |
|---|---|
| `cnpj` / `cnpj_formatado` | The company's tax ID, digits-only and formatted. |
| `razao_social` | Exact legal name from the federal registry (unmodified). |
| `nome_fantasia` | Trade name, when declared. |
| `cnae_principal` | Primary economic activity code (what the company actually does). |
| `municipio` / `uf` | City and state of the establishment. |
| `porte` | Declared size (MEI/micro, small, other). |
| `data_abertura` | Opening date (YYYY-MM-DD). |
| `tem_email` / `tem_telefone` | Whether the registry has an email/phone on file for this company — useful to estimate contactability before running [CNPJ Lookup](https://apify.com/gangary/cnpj-lookup). |

### Use cases

- **Build a prospecting list by niche + region** — every active dental clinic in SP, every trucking company in the South, every software house in your city
- **Size a market (TAM)** — how many active companies exist per CNAE per state, with zero sampling bias (it's the full registry)
- **Feed your sales pipeline** — Discovery finds them → [CNPJ Lookup](https://apify.com/gangary/cnpj-lookup) pulls addresses, partners and contacts → [Lead Enricher](https://apify.com/gangary/lead-enricher-icp) verifies and scores them
- **Territory planning** — split a segment by city/size before assigning reps

### Pricing (Pay per event)

| Event | When | Price |
|---|---|---|
| `actor-start` | once per run | $0.005 |
| `company-found` | per company returned | $0.002 |

A 500-company list costs $0.005 + 500 × $0.002 = **$1.005**. A 5,000-company segment costs **$10.005**. Runs that find nothing only pay the start fee.

### Where the data comes from

The official **CNPJ open dataset published by Receita Federal** (Brazil's Federal Revenue), rebuilt into a fast index **every month** — you always query the latest published registry snapshot, with only **active** (situação ATIVA) establishments included.

### Is this compliant?

Yes — the CNPJ registry is **public information** that Receita Federal itself publishes as open data. No scraping, no logins, no private or behind-auth data. LGPD note: these are company registry records, published officially for public consultation.

### Limitations

- Data is a **monthly snapshot** of the official registry — a company opened yesterday appears after the next monthly rebuild.
- Returns registry firmographics, **not contact details** — `tem_email`/`tem_telefone` tell you they exist; [CNPJ Lookup](https://apify.com/gangary/cnpj-lookup) retrieves them per company.
- Filters use the **primary** CNAE (secondary activities are not indexed).
- Only **active** companies — closed (BAIXADA) or suspended ones are excluded by design.

### From the same maker

- **[CNPJ Lookup — Brazilian Company Registry Data](https://apify.com/gangary/cnpj-lookup)** — full official record per CNPJ: status, address, partners, capital, phone and email when on file.
- **[Lead Enricher & ICP Scorer](https://apify.com/gangary/lead-enricher-icp)** — clean, verify, dedupe and score any lead list 0–100 against your ideal customer profile.

# Actor input Schema

## `cnae` (type: `string`):

Codigo completo (8630-5/04) ou prefixo (8630, 86) da atividade economica.

## `ufs` (type: `array`):

Siglas de 2 letras (ex: MG, SP). Pelo menos 1 e obrigatoria.

## `municipio` (type: `string`):

Nome do municipio (com ou sem acento). Filtra dentro das UFs escolhidas.

## `porte` (type: `string`):

Restringe pelo porte declarado na Receita.

## `limit` (type: `integer`):

Maximo de empresas retornadas nessa execucao.

## `offset` (type: `integer`):

Pula os N primeiros resultados (paginacao).

## Actor input object example

```json
{
  "cnae": "8630-5/04",
  "ufs": [
    "MG"
  ],
  "limit": 100,
  "offset": 0
}
```

# 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 = {
    "cnae": "8630-5/04",
    "ufs": [
        "MG"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("gangary/cnpj-discovery").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 = {
    "cnae": "8630-5/04",
    "ufs": ["MG"],
}

# Run the Actor and wait for it to finish
run = client.actor("gangary/cnpj-discovery").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 '{
  "cnae": "8630-5/04",
  "ufs": [
    "MG"
  ]
}' |
apify call gangary/cnpj-discovery --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Brazilian Companies Finder — by CNAE & State (CNPJ Discovery)",
        "description": "Find every active Brazilian company matching a CNAE activity code and state in seconds — no scraping, powered by an official Receita Federal data index. Filter further by city and company size. Get CNPJ, legal name, trade name, activity, city, size and opening date.",
        "version": "0.1",
        "x-build-id": "564ta7c0g2TQddZtp"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/gangary~cnpj-discovery/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-gangary-cnpj-discovery",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/gangary~cnpj-discovery/runs": {
            "post": {
                "operationId": "runs-sync-gangary-cnpj-discovery",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/gangary~cnpj-discovery/run-sync": {
            "post": {
                "operationId": "run-sync-gangary-cnpj-discovery",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "cnae",
                    "ufs"
                ],
                "properties": {
                    "cnae": {
                        "title": "CNAE (codigo ou prefixo)",
                        "type": "string",
                        "description": "Codigo completo (8630-5/04) ou prefixo (8630, 86) da atividade economica."
                    },
                    "ufs": {
                        "title": "UFs",
                        "type": "array",
                        "description": "Siglas de 2 letras (ex: MG, SP). Pelo menos 1 e obrigatoria.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "municipio": {
                        "title": "Municipio (opcional)",
                        "type": "string",
                        "description": "Nome do municipio (com ou sem acento). Filtra dentro das UFs escolhidas."
                    },
                    "porte": {
                        "title": "Porte (opcional)",
                        "enum": [
                            "micro",
                            "pequena",
                            "demais"
                        ],
                        "type": "string",
                        "description": "Restringe pelo porte declarado na Receita."
                    },
                    "limit": {
                        "title": "Limite de resultados",
                        "minimum": 1,
                        "maximum": 5000,
                        "type": "integer",
                        "description": "Maximo de empresas retornadas nessa execucao.",
                        "default": 100
                    },
                    "offset": {
                        "title": "Offset",
                        "minimum": 0,
                        "type": "integer",
                        "description": "Pula os N primeiros resultados (paginacao).",
                        "default": 0
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
