# Migrate from BrasilAPI

> How to replace BrasilAPI's CNPJ and CEP lookups with the CNPJá API: matching operations and fields, codes, errors and maximum data age.

This guide moves an integration with BrasilAPI's CNPJ and CEP lookups to the CNPJá API. Facts about BrasilAPI come from the documentation and code it publishes; facts about CNPJá come from the [Reference](https://cnpja.com/en-us/docs/api/reference).

## Overview

- The CNPJ and CEP lookups become [Lookup CNPJ](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d) and [Lookup CEP](https://cnpja.com/en-us/docs/api/reference#tag/postal-codes/GET/v2/postal-codes/%7bcode%7d).
- Fields change name and structure: the CNPJá response uses English names, groups the company under `company` and the address under `address`, and returns phones, emails and partners as lists of objects.
- Numeric codes, such as `situacao_cadastral` and `codigo_porte`, become objects with `code` and `label`, where `code` is a stable text value, such as `ACTIVE`.
- The Simples Nacional and MEI options and the tax regime leave the default response and are requested with `expand=company.taxRegime`, which needs an API key.
- The CNPJá API requires an API key, except for Lookup CNPJ and Lookup CEP with no query parameters at all, and is billed per query.
- Every response carries `updatedAt`, and `maxAge` sets the maximum accepted data age.
- Errors carry `status` and a stable `code` instead of `name` and `type`.

Effort: low to medium. BrasilAPI's lookups take no query parameters, so the work lies in replacing the layer that reads fields and converts codes.

## Prerequisites

- **Account and key:** [sign up](https://cnpja.com/en-us/signup) and create a key in [API keys](https://cnpja.com/en-us/organizations/current/api-keys). The walkthrough is in [First request](https://cnpja.com/en-us/docs/api/first-request).
- **Authentication:** BrasilAPI's documentation doesn't describe authentication. In CNPJá, send the key as the entire value of the `Authorization` header, with no prefix: `Authorization: YOUR_API_KEY`. With `Bearer`, the request is rejected with `401` `API_KEY_INVALID`. See [Authentication](https://cnpja.com/en-us/docs/api/reference#description/authentication).
- **Base URL:** `https://api.cnpja.com/v2`, instead of `https://brasilapi.com.br/api`.
- **What carries over:** the 14-character CNPJ, alphanumeric included, the 8-digit CEP, the 7-digit [IBGE municipality code](https://www.ibge.gov.br/explica/codigos-dos-municipios.php), the official [CNAE](https://concla.ibge.gov.br/busca-online-cnae.html?view=estrutura), [legal nature](https://concla.ibge.gov.br/estrutura/natjur-estrutura/natureza-juridica-2021), partner role and status reason codes, now as text, the masked partner CPF in the same format, such as `***112108**`, and dates in `YYYY-MM-DD` format.
- **What changes:** field names and the response structure, the numeric codes for registration status, company size, head office or branch, and partner type, and a CNPJ or CEP with punctuation in the URL. The CEP coordinates and time zone and the `service` field are gone.

## Matching operations

| BrasilAPI | CNPJá | Notes |
|---|---|---|
| `GET /cnpj/v1/{cnpj}` | [Lookup CNPJ](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d) | Tax regime, Simples Nacional and MEI require `expand=company.taxRegime`. See [CNPJ lookup](https://cnpja.com/en-us/docs/api/cnpj-lookup). |
| `GET /cep/v1/{cep}` | [Lookup CEP](https://cnpja.com/en-us/docs/api/reference#tag/postal-codes/GET/v2/postal-codes/%7bcode%7d) | See [CEP and addresses](https://cnpja.com/en-us/docs/api/postal-codes). |
| `GET /cep/v2/{cep}` | [Lookup CEP](https://cnpja.com/en-us/docs/api/reference#tag/postal-codes/GET/v2/postal-codes/%7bcode%7d) | No coordinates or time zone. |
| `GET /cep/v3/{cep}` | [Lookup CEP](https://cnpja.com/en-us/docs/api/reference#tag/postal-codes/GET/v2/postal-codes/%7bcode%7d) | No coordinates. To find CEPs by their first digits or by address, use `search` in [Search CEP](https://cnpja.com/en-us/docs/api/reference#tag/postal-codes/GET/v2/postal-codes), with a key. |

BrasilAPI's other services, such as banks, exchange rates, holidays, FIPE, IBGE and the CVM registries, have no CNPJá equivalent and are out of scope for this guide.

The CNPJá API also offers operations with no BrasilAPI equivalent, such as [Lookup company](https://cnpja.com/en-us/docs/api/reference#tag/companies/GET/v2/companies/%7bid%7d), which lists the establishments of a CNPJ root, [Search CNPJ](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments) and [Issue CNPJ dossier](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d/dossier).

## Request example

BrasilAPI:

```http
GET /api/cnpj/v1/37335118000180 HTTP/1.1
Host: brasilapi.com.br
```

CNPJá, with the tax regime:

```http
GET /v2/establishments/37335118000180?expand=company.taxRegime HTTP/1.1
Host: api.cnpja.com
Authorization: YOUR_API_KEY
```

## Parameters

| BrasilAPI | CNPJá | Notes |
|---|---|---|
| `cnpj` in the path | `taxId` in the path | BrasilAPI accepts the CNPJ with or without punctuation. CNPJá requires 14 characters without punctuation, with uppercase letters and valid check digits; any other format is rejected with `400`. |
| `cep` in the path | `code` in the path | BrasilAPI accepts the CEP with or without a hyphen. CNPJá validates only the length: send the 8 digits without a hyphen and with leading zeros. `01310-930` is rejected with `400`. |
| No equivalent | `maxAge` | Maximum data age in Lookup CNPJ, from `5m` to `1y`, default `45d`. See [Max age and partial success](https://cnpja.com/en-us/docs/api/max-age). |
| No equivalent | `expand=company.taxRegime` | Needed for the Simples Nacional, MEI and tax regime fields. |
| No equivalent | `expand=stateRegistry`, `expand=suframa` | State and SUFRAMA registrations. See [State registrations](https://cnpja.com/en-us/docs/api/state-registrations) and [SUFRAMA](https://cnpja.com/en-us/docs/api/suframa). |
| No equivalent | `expand=address.coordinates` | Latitude and longitude of the establishment. See [Location and maps](https://cnpja.com/en-us/docs/api/location). |

`maxAge` and `expand` require an API key: a request without a key and with any query parameter is rejected with `401` `API_KEY_MISSING`.

## Response fields

Paths with `[]` mean each item of a list. For the Simples Nacional, MEI and tax regime fields, the CNPJá column applies only with `expand=company.taxRegime`.

### Identification and status

| BrasilAPI | CNPJá | Notes |
|---|---|---|
| `cnpj` | `taxId` | |
| `identificador_matriz_filial` | `type.code` | `1` becomes `HEAD` and `2` becomes `BRANCH`. |
| `descricao_identificador_matriz_filial` | `type.label` | `Matriz` or `Filial`. |
| `nome_fantasia` | `tradeName` | `null` when there is no trade name. |
| `data_inicio_atividade` | `incorporationDate` | |
| `situacao_cadastral` | `status.code` | `1` becomes `VOID`, `2` becomes `ACTIVE`, `3` becomes `SUSPENDED`, `4` becomes `NONCOMPLIANT` and `8` becomes `CLOSED`. |
| `descricao_situacao_cadastral` | `status.label` | Such as `Ativa`. |
| `data_situacao_cadastral` | `statusDate` | |
| `motivo_situacao_cadastral` | `statusReason.code` | A number in BrasilAPI, 2-character text in CNPJá. `statusReason` appears only when the establishment isn't active. |
| `descricao_motivo_situacao_cadastral` | `statusReason.label` | |
| `situacao_especial` | `specialStatus.label` | `specialStatus.code` carries the 3-character code. Absent when there is no special status. |
| `data_situacao_especial` | `specialStatusDate` | Absent when there is no special status. |
| No equivalent | `updatedAt` | Last update from the [Receita Federal](https://solucoes.receita.fazenda.gov.br/Servicos/cnpjreva/). |

### Address and contacts

| BrasilAPI | CNPJá | Notes |
|---|---|---|
| `descricao_tipo_de_logradouro`, `logradouro` | `address.street` | CNPJá has no separate field for the street type. In the Reference example, `street` is `Avenida Brigadeiro Faria Lima`. |
| `numero` | `address.number` | |
| `complemento` | `address.details` | |
| `bairro` | `address.district` | |
| `municipio` | `address.city` | |
| `codigo_municipio_ibge` | `address.municipality` | A number in BrasilAPI, 7-digit text in CNPJá. |
| `codigo_municipio` | No equivalent | CNPJá identifies the municipality by its name, in `address.city`, and its IBGE code. |
| `uf` | `address.state` | |
| `cep` | `address.postalCode` | |
| `codigo_pais` | `address.country.code` | A numeric code in BrasilAPI, a 2-letter country code in CNPJá, such as `BR`. |
| `pais` | `address.country.label` | |
| `nome_cidade_no_exterior` | No equivalent | |
| `ddd_telefone_1`, `ddd_telefone_2` | `phones[].number` | Area code and number become E.164, such as `+5511971564144`. `phones[].type.code` is `LANDLINE` or `MOBILE`. |
| `ddd_fax` | No equivalent | |
| `email` | `emails[].address` | A string in BrasilAPI, a list in CNPJá. `emails[].type.code` carries the email type. |

### Activities

| BrasilAPI | CNPJá | Notes |
|---|---|---|
| `cnae_fiscal` | `primaryActivity.code` | A number in BrasilAPI, 7-digit text in CNPJá. |
| `cnae_fiscal_descricao` | `primaryActivity.label` | |
| `cnaes_secundarios[].codigo` | `secondaryActivities[].code` | 7-digit text. |
| `cnaes_secundarios[].descricao` | `secondaryActivities[].label` | |

### Company and partners

| BrasilAPI | CNPJá | Notes |
|---|---|---|
| `razao_social` | `company.legalName` | |
| `capital_social` | `company.shareCapital` | An integer in BrasilAPI, a number with cents in CNPJá, such as `99999.99`. |
| `codigo_natureza_juridica` | `company.legalNature.code` | A number in BrasilAPI, 4-digit text in CNPJá. |
| `natureza_juridica` | `company.legalNature.label` | |
| `codigo_porte` | `company.size.code` | `1` becomes `MICRO`, `3` becomes `SMALL`, and `0` (size not reported) and `5` become `OTHER`. |
| `porte` | `company.size.label` | |
| `ente_federativo_responsavel` | `company.federativeEntity.label` | `company.federativeEntity.code` holds `BR` for the União, the UF abbreviation or the IBGE municipality code. Absent outside public administration. |
| `qualificacao_do_responsavel` | No equivalent | |
| `qsa[]` | `company.partners[]` | See [Partners and people](https://cnpja.com/en-us/docs/api/partners). |
| `qsa[].identificador_de_socio` | `company.partners[].person.type.code` | `1` becomes `ESTABLISHMENT`, `2` becomes `INDIVIDUAL` and `3` becomes `FOREIGNER`. CNPJá also has `UNKNOWN`, a partner known only by name. |
| `qsa[].nome_socio` | `company.partners[].person.legalName` | |
| `qsa[].cnpj_cpf_do_socio` | `company.partners[].person.taxId` | Masked CPF or CNPJ. `null` for `FOREIGNER` and `UNKNOWN`. |
| `qsa[].codigo_qualificacao_socio` | `company.partners[].role.code` | A number in BrasilAPI, 2-character text in CNPJá. |
| `qsa[].qualificacao_socio` | `company.partners[].role.label` | |
| `qsa[].data_entrada_sociedade` | `company.partners[].admissionDate` | |
| `qsa[].codigo_faixa_etaria`, `qsa[].faixa_etaria` | `company.partners[].person.ageGroup` | Text with no `label`, such as `41-50`. Present for individuals only. |
| `qsa[].codigo_pais` | `company.partners[].person.domicileCountry.code` | 2-letter country code. |
| `qsa[].pais` | `company.partners[].person.domicileCountry.label` | |
| `qsa[].cpf_representante_legal` | `company.partners[].legalRepresentative.person.taxId` | `legalRepresentative` appears only when the partner has a legal representative. |
| `qsa[].nome_representante_legal` | `company.partners[].legalRepresentative.person.legalName` | |
| `qsa[].codigo_qualificacao_representante_legal` | `company.partners[].legalRepresentative.role.code` | 2-character text. |
| `qsa[].qualificacao_representante_legal` | `company.partners[].legalRepresentative.role.label` | |
| No equivalent | `company.partners[].person.id` | Stable CNPJá person ID, used with [Lookup person](https://cnpja.com/en-us/docs/api/reference#tag/people/GET/v2/people/%7bid%7d). |

### Tax regime

| BrasilAPI | CNPJá | Notes |
|---|---|---|
| `opcao_pelo_simples` | `company.taxRegime.type.code` | `true` matches `SIMPLES_NACIONAL`, `SIMPLES_NACIONAL_HYBRID` or `SIMPLES_NACIONAL_SIMEI`. CNPJá always returns a regime, never `null`. |
| `data_opcao_pelo_simples` | `company.taxRegime.simplesNacionalStartDate` | Start of the current [Simples Nacional](https://consopt.www8.receita.fazenda.gov.br/consultaoptantes) period. Present only when `type.code` is `SIMPLES_NACIONAL`, `SIMPLES_NACIONAL_HYBRID` or `SIMPLES_NACIONAL_SIMEI`, and may be `null`. |
| `data_exclusao_do_simples` | `company.taxRegime.timeline[].endDate` | With `company.taxRegime.view=DETAILED`, in items whose `type.code` is `SIMPLES_NACIONAL_PERIOD`. |
| `opcao_pelo_mei` | `company.taxRegime.type.code` | `true` matches `SIMPLES_NACIONAL_SIMEI`. |
| `data_opcao_pelo_mei` | `company.taxRegime.simeiStartDate` | Start of the current SIMEI period. Present only when `type.code` is `SIMPLES_NACIONAL_SIMEI`, and may be `null`. |
| `data_exclusao_do_mei` | `company.taxRegime.timeline[].endDate` | With `company.taxRegime.view=DETAILED`, in items whose `type.code` is `SIMEI_PERIOD`. |
| `regime_tributario[].forma_de_tributacao` | `company.taxRegime.timeline[].type.code` | With `company.taxRegime.view=DETAILED`, the regime history returns one item per period: `ACTUAL_PROFIT_PERIOD`, `PRESUMED_PROFIT_PERIOD` or `ARBITRATED_PROFIT_PERIOD` for the years declared in the ECF, `SIMPLES_NACIONAL_PERIOD` and `SIMEI_PERIOD` for Simples Nacional and SIMEI periods, and `REGULAR_IBS_PERIOD` and `REGULAR_CBS_PERIOD` for IBS and CBS regular regime periods. The current regime is in `company.taxRegime.type.code`: `ACTUAL_PROFIT`, `PRESUMED_PROFIT`, `ARBITRATED_PROFIT`, `SIMPLES_NACIONAL`, `SIMPLES_NACIONAL_HYBRID`, `SIMPLES_NACIONAL_SIMEI` or `NOT_APPLICABLE`. See [Regime history](https://cnpja.com/en-us/docs/api/tax-regime#regime-history). |
| `regime_tributario[].ano` | `company.taxRegime.timeline[].startDate`, `company.taxRegime.timeline[].endDate` | With `company.taxRegime.view=DETAILED`. Each year declared in the ECF becomes a period from January 1 to December 31; the year is that of `startDate`. |
| `regime_tributario[].cnpj_da_scp` | No equivalent | |
| `regime_tributario[].quantidade_de_escrituracoes` | No equivalent | |

`SIMPLES_NACIONAL_HYBRID` identifies Simples Nacional optants that also opt into the IBS or CBS regular regime. For them, `company.taxRegime.view=DETAILED` also returns `company.taxRegime.regularIbsStartDate` and `company.taxRegime.regularCbsStartDate`, the start of the current IBS and CBS regular regime periods, which come only from live queries at the Simples Nacional. Either may be `null` when the company opts into only one of the two.

The regime rules, including when the regime is estimated, are in [Tax regime](https://cnpja.com/en-us/docs/api/tax-regime).

### CEP

| BrasilAPI | CNPJá | Notes |
|---|---|---|
| `cep` | `code` | |
| `state` | `state` | |
| `city` | `city` | |
| `neighborhood` | `district` | |
| `street` | `street` | |
| `ibge.city` | `municipality` | |
| `ibge.state` | No equivalent | CNPJá returns only the UF abbreviation. |
| `service` | No equivalent | CNPJá uses only the [Correios DNE](https://buscacepinter.correios.com.br/app/endereco/index.php), and `updatedAt` gives the last update. |
| `location.coordinates.latitude`, `location.coordinates.longitude` | No equivalent | Coordinates exist only for establishments, with `expand=address.coordinates`. |
| `location.type` | No equivalent | |
| `timezoneName` | No equivalent | |
| No equivalent | `type`, `status`, `name`, `number`, `details` | CEP type and status, and recipient data. See [CEP and addresses](https://cnpja.com/en-us/docs/api/postal-codes). |

### Formats

- Codes become text: CNAE, legal nature, role, status reason and IBGE code arrive as fixed-length text, never as numbers.
- Classified fields carry `code` and `label`. Use `code` in your logic; `label` is for display only, follows the response language and may change without notice.
- Values with no record come as `null`, and lists with no items come empty. Resources not requested in `expand` are absent.
- Fields that the BrasilAPI example shows as empty text, such as `ddd_telefone_2` and `situacao_especial`, become fewer list items, `null` or an absent field in CNPJá, as shown in the tables above.

See [Response format](https://cnpja.com/en-us/docs/api/responses).

## Behavior differences

### Freshness and caching

In CNPJá, each resource comes from the cache while it is within `maxAge` and is queried live, before the response, when it is older or was never fetched. `maxAge` ranges from `5m` to `1y`, with a `45d` default, and each resource reports its last update in its own `updatedAt`. Lookup CEP doesn't accept `maxAge` and serves cached data only. See [Max age and partial success](https://cnpja.com/en-us/docs/api/max-age).

### Partial success

When a live query fails or runs past its [time limit](https://cnpja.com/en-us/docs/api/limits-and-errors#timeout-and-size), the response is `206`, with the same shape as `200`: the affected resource keeps its cached data, or comes back empty if it was never fetched, and is not billed. With no cached data to fall back on, such as on a CNPJ's first lookup, the request fails instead of returning `206`. Treat `206` as success and compare each resource's `updatedAt` with the limit you asked for. See [Partial success](https://cnpja.com/en-us/docs/api/reference#description/partial-success).

### Errors

BrasilAPI returns errors with `name`, `message` and `type`, and CEP errors may add `errors`, with the details of each failure, such as one item per provider queried. In CNPJá, every error body carries `status`, `code`, `message` and `traceId`. Handle errors by `code`, which is stable, and use `message` for display only. See [Limits and errors](https://cnpja.com/en-us/docs/api/limits-and-errors).

| BrasilAPI | CNPJá |
|---|---|
| `400` `BadRequestError` on CNPJ or `CepPromiseError` on CEP | `400` `REQUEST_VALIDATION_FAILED` |
| `404` `NotFoundError` on CNPJ | `404` `ESTABLISHMENT_NOT_FOUND` |
| `404` `CepPromiseError` on CEP | `404` `POSTAL_CODE_NOT_FOUND` |
| `503` `ServiceUnavailableError` on CNPJ, when the source fails or takes over 5 seconds | `206` with the cached data, or `500` or `504` without it, as explained under partial success above |
| `500`, with `type` set to `internal_error` | `500` `UNEXPECTED_ERROR` |

CNPJá also has `401` for a missing or invalid key, `402` for a used-up quota or overage budget, `429` for exceeded limits and `504` for a request that runs past its [time limit](https://cnpja.com/en-us/docs/api/limits-and-errors#timeout-and-size).

### Limits

With a key, the requests-per-second and concurrent-request limits apply to the whole organization, across all of its keys, and follow its plan; without a key, they apply to each source IP. The values are in [Usage limits](https://cnpja.com/en-us/docs/api/limits-and-errors#usage-limits). Above them, the response is `429`, not billed. Each request has a maximum duration, and the client timeout must stay above it, as shown in [Timeout and size](https://cnpja.com/en-us/docs/api/limits-and-errors#timeout-and-size).

### Billing

Each resource in the response is billed separately, as a live query, which costs more, or a cached query, and each unit has its own quota in the plan, renewed every month. On Pro, the quota of each unit can grow with [packs](https://cnpja.com/en-us/docs/billing/packs-and-budget#packs), and the organization can set a budget to pay for each query beyond the quota at the per-query overage price, so an exhausted quota does not have to stop the integration. When a quota runs out with no overage budget, or the month's budget runs out, every request made with one of the organization's keys gets `402`, as explained in [Quota used up](https://cnpja.com/en-us/docs/billing/quota-exhausted#api); on Free, which has no packs or budget, this happens as soon as the quota runs out. Requests without a key, rejected requests and server failures are not billed, as listed in [What is not charged](https://cnpja.com/en-us/legal/metering#not-charged). In Lookup CNPJ, the registration and `company.taxRegime` count separately. A `404` is billed too, as detailed in [What is charged even without a useful result](https://cnpja.com/en-us/legal/metering#charged-without-result). Responses carry no cost headers: track usage under [Usage](https://cnpja.com/en-us/organizations/current/usage). See [Queries and quota](https://cnpja.com/en-us/docs/billing/queries-and-quotas), what each operation consumes in the [Metering Rules](https://cnpja.com/en-us/legal/metering#api) and [Pricing](https://cnpja.com/en-us/pricing).

### Language and labels

`label` values and error messages come in Portuguese by default; send `Accept-Language: en-US` to get them in English. Codes, field names and official source data are never translated. Use `code` in your logic and `label` for display only. See [Language](https://cnpja.com/en-us/docs/api/reference#description/language).

## No equivalent

- CEP coordinates, geometry type and time zone.
- The Receita Federal municipality code (`codigo_municipio`), the IBGE UF code and the city name abroad.
- Fax number (`ddd_fax`).
- Role of the responsible person (`qualificacao_do_responsavel`).
- SCP CNPJ and bookkeeping count from `regime_tributario`.

## Step by step

1. Create the account and the API key, and store the key in an environment variable.
2. Change the base URL to `https://api.cnpja.com/v2` and the paths as shown in the matching operations table.
3. Send the key in `Authorization`, without `Bearer`.
4. Strip punctuation from the CNPJ and CEP, keep leading zeros and use uppercase letters in the CNPJ.
5. Add `expand=company.taxRegime` wherever you use Simples Nacional, MEI or tax regime data.
6. Rewrite field reading with the tables above, converting numeric codes into `code`.
7. Handle errors by `code`, treat `206` as success and set a client timeout above a request's maximum duration, given in [Timeout and size](https://cnpja.com/en-us/docs/api/limits-and-errors#timeout-and-size).
8. Validate the integration with a key and check consumption in [Requests](https://cnpja.com/en-us/organizations/current/usage-events). Lookup CNPJ and Lookup CEP also work without a key when the URL has no query parameters, as explained in [Public access](https://cnpja.com/en-us/docs/api/public-access).
9. Switch traffic and watch errors and consumption over the first few days.

## Sources for this comparison

What this page says about BrasilAPI comes from its public documentation:

- BrasilAPI documentation: the CNPJ and CEP operations, the response fields and the errors.
- BrasilAPI repository: the code and the sources of each operation.

Sources accessed on November 19, 2026.

Third-party trademarks on this page are used only to identify them, with no affiliation or endorsement ([Terms of Use](https://cnpja.com/en-us/legal/terms#data)).
