# Migrate from CNPJá v1 to v2

> How to replace each CNPJá API v1 operation with v2, using the same key: new paths, resources in expand, certificates in one PDF and cursor pagination.

The v1 API organizes lookups by source, with one operation for the [Receita Federal](https://solucoes.receita.fazenda.gov.br/Servicos/cnpjreva/), another for the [Simples Nacional](https://consopt.www8.receita.fazenda.gov.br/consultaoptantes), another for the [CCC](https://dfe-portal.svrs.rs.gov.br/Nfe/Ccc) and another for [SUFRAMA](https://www4.suframa.gov.br/cadsuf/#/menu-externo), plus CNPJ lookup and search. In v2, a CNPJ's data comes from [Lookup CNPJ](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d), with optional resources requested in `expand`, and the certificates come from a single operation. Every v2 detail is in the [Reference](https://cnpja.com/en-us/docs/api/reference).

## Overview

- Paths gain the `/v2` prefix and new names: `/office` becomes `/v2/establishments`, `/person` becomes `/v2/people` and `/zip` becomes `/v2/postal-codes`, on the same host and with the same API key.
- The standalone lookups `/rfb`, `/simples`, `/ccc` and `/suframa` become resources of Lookup CNPJ, or of [Lookup CPF](https://cnpja.com/en-us/docs/api/reference#tag/individuals/GET/v2/individuals/%7btaxId%7d) when the document is a CPF.
- The boolean parameters `simples`, `suframa` and `geocoding` and the `registrations` list become `expand` values.
- `maxAge` now takes a unit, such as `45d`, and `strategy`, `maxStale` and `sync` are gone.
- Fields are renamed: `id` and `text` become `code` and `label`, numeric codes become fixed-length strings, and booleans such as `head` become codes, such as `HEAD`.
- The four certificates become a single PDF from [Issue CNPJ dossier](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d/dossier), or from Issue CPF dossier for a CPF, with the documents chosen in `certificates`.
- Pagination replaces `token`, `next` and `count` with `cursor`, `nextCursor` and `total`.

Effort: medium. There is no new account, key or quota; the work is rewriting the calls and the field parsing, operation by operation.

## Prerequisites

- **Account and key:** v1 and v2 use the same API keys, from the same organization. If you don't have one yet, see [First request](https://cnpja.com/en-us/docs/api/first-request).
- **Authentication:** same as v1. 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`. v1 answers on the same host, without the version prefix.
- **What carries over:** keys, organization, plan quotas and request limits. Both versions consume the same live and cached query quotas.
- **Existing data:** the list, person and company IDs from v1 are valid in v2. Lists created in v1 are the same ones [Search lists](https://cnpja.com/en-us/docs/api/reference#tag/lists/GET/v2/lists) returns.
- **What changes:** the paths, the parameters, the response format, the codes of classified values and how you track usage.

## Matching operations

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `GET /office/{taxId}` | [Lookup CNPJ](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d) | See [CNPJ lookup](https://cnpja.com/en-us/docs/api/cnpj-lookup). |
| `GET /office` | [Search CNPJ](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments) | Filters renamed. See [CNPJ search and lists](https://cnpja.com/en-us/docs/api/cnpj-search). |
| `GET /office/{taxId}/map` | [Render CNPJ map](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d/map) | See [Location and maps](https://cnpja.com/en-us/docs/api/location). |
| `GET /office/{taxId}/street` | [Render CNPJ street view](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d/street-view) | The path ends in `street-view`. v1 declared PNG; v2 returns a JPEG. |
| `GET /company/{companyId}` | [Lookup company](https://cnpja.com/en-us/docs/api/reference#tag/companies/GET/v2/companies/%7bid%7d) | Same CNPJ root, 8 characters. |
| `GET /person/{personId}` | [Lookup person](https://cnpja.com/en-us/docs/api/reference#tag/people/GET/v2/people/%7bid%7d) | Same ID. See [Partners and people](https://cnpja.com/en-us/docs/api/partners). |
| `GET /person` | [Search people](https://cnpja.com/en-us/docs/api/reference#tag/people/GET/v2/people) | |
| `GET /rfb` | [Lookup CNPJ](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d) | No `expand`. The CNPJ goes in the path, not in the `taxId` parameter. |
| `GET /rfb/certificate` | [Issue CNPJ dossier](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d/dossier) | `certificates=RFB_REGISTRATION,RFB_PARTNERS`. See [Certificates](https://cnpja.com/en-us/docs/api/certificates). |
| `GET /simples` | [Lookup CNPJ](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d) | `expand=company.taxRegime`. See [Tax regime](https://cnpja.com/en-us/docs/api/tax-regime). |
| `GET /simples/certificate` | [Issue CNPJ dossier](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d/dossier) | `certificates=SIMPLES_NACIONAL_OPTION`. |
| `GET /ccc` with a CNPJ | [Lookup CNPJ](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d) | `expand=stateRegistry` and `stateRegistry.states`. |
| `GET /ccc` with a CPF | [Lookup CPF](https://cnpja.com/en-us/docs/api/reference#tag/individuals/GET/v2/individuals/%7btaxId%7d) | `expand=stateRegistry` and `stateRegistry.states`, required. |
| `GET /ccc/certificate` | [Issue CNPJ dossier](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d/dossier) or [Issue CPF dossier](https://cnpja.com/en-us/docs/api/reference#tag/individuals/GET/v2/individuals/%7btaxId%7d/dossier) | `certificates=CCC_REGISTRATIONS`. |
| `GET /suframa` with a CNPJ | [Lookup CNPJ](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d) | `expand=suframa`. |
| `GET /suframa` with a CPF | [Lookup CPF](https://cnpja.com/en-us/docs/api/reference#tag/individuals/GET/v2/individuals/%7btaxId%7d) | `expand=suframa`. |
| `GET /suframa/certificate` | [Issue CNPJ dossier](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d/dossier) or [Issue CPF dossier](https://cnpja.com/en-us/docs/api/reference#tag/individuals/GET/v2/individuals/%7btaxId%7d/dossier) | `certificates=SUFRAMA_REGISTRATION`. |
| `GET /zip/{code}` | [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). |
| `POST /list` | [Create list](https://cnpja.com/en-us/docs/api/reference#tag/lists/POST/v2/lists) | `type` and `items` become required. |
| `GET /list` | [Search lists](https://cnpja.com/en-us/docs/api/reference#tag/lists/GET/v2/lists) | |
| `GET /list/{listId}` | [Lookup list](https://cnpja.com/en-us/docs/api/reference#tag/lists/GET/v2/lists/%7blistId%7d) | |
| `PATCH /list/{listId}` | [Update list](https://cnpja.com/en-us/docs/api/reference#tag/lists/PATCH/v2/lists/%7blistId%7d) | |
| `DELETE /list/{listId}` | [Delete list](https://cnpja.com/en-us/docs/api/reference#tag/lists/DELETE/v2/lists/%7blistId%7d) | |
| `POST /list/{listId}/export` and the export lookups | No equivalent | Already deprecated in v1. To read the CNPJs in a list, use Search CNPJ with `lists.some`. |
| `GET /credit` | No equivalent | Usage is shown in the app, under [Usage](https://cnpja.com/en-us/organizations/current/usage). |

## Request example

The main lookup, with Simples Nacional and state registrations.

CNPJá v1:

```http
GET /office/37335118000180?simples=true&registrations=ORIGIN&maxAge=30 HTTP/1.1
Host: api.cnpja.com
Authorization: YOUR_API_KEY
```

CNPJá v2:

```http
GET /v2/establishments/37335118000180?expand=company.taxRegime,stateRegistry&stateRegistry.states=ORIGIN&maxAge=30d HTTP/1.1
Host: api.cnpja.com
Authorization: YOUR_API_KEY
```

## Parameters

### Lookup CNPJ

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `taxId` (path) | `taxId` (path) | 14-character CNPJ, without punctuation. |
| `maxAge` | `maxAge` | An integer in days in v1, a string with a unit in v2: `maxAge=45` becomes `maxAge=45d`. The default is still 45 days. v2 accepts `5m` to `1y`. |
| `strategy=CACHE_IF_FRESH` or `CACHE_IF_ERROR` | `maxAge` | This is v2's default behavior: cached data within `maxAge`, a live query beyond it, and `206` with the cached data if the live query fails. |
| `strategy=ONLINE` | A small `maxAge` | v1 itself suggested `maxAge=1`. In v2, the smallest value is `5m`. |
| `strategy=CACHE` | No equivalent | Lookup CNPJ always queries live the resources older than `maxAge`, which goes up to `1y`. |
| `maxStale` | No equivalent | In v2, the `206` response carries the cached data of the resource whose live query failed. |
| `sync` | No equivalent | v2 has no cost headers. |
| `simples=true` | `expand=company.taxRegime` | Simples Nacional and MEI opt-in, and the tax regime. |
| `simplesHistory=true` | `expand=company.taxRegime` and `company.taxRegime.view=DETAILED` | The history comes in `company.taxRegime.timeline`. |
| `registrations` | `expand=stateRegistry` and `stateRegistry.states` | Same values: `ORIGIN`, `ALL` or UF abbreviations. `stateRegistry.states` defaults to `ORIGIN`. |
| `registrationsSource` | No equivalent | v2 uses the CCC only. |
| `suframa=true` | `expand=suframa` | |
| `geocoding=true` | `expand=address.coordinates` | |
| `links` | No equivalent | Call the certificate, map and street view operations directly, with a key. |
| No equivalent | `stateRegistry.view=DETAILED` | Activity, address, sublimit and authorized tax documents of each registration. See [State registrations](https://cnpja.com/en-us/docs/api/state-registrations). |
| No equivalent | `company.taxRegime.maxAge`, `stateRegistry.maxAge`, `suframa.maxAge` | A separate age limit for each resource. See [Max age and partial success](https://cnpja.com/en-us/docs/api/max-age). |

Send multiple `expand` values comma-separated or by repeating the parameter. The rules are in [Response expansion](https://cnpja.com/en-us/docs/api/reference#description/response-expansion).

### Standalone lookups and certificates

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `taxId` (URL) in `/rfb`, `/simples`, `/ccc`, `/suframa` and the certificates | `taxId` (path) | In v2, the document is part of the path. CNPJs go in `/v2/establishments/` and CPFs in `/v2/individuals/`. |
| `maxAge` in `/simples` | `company.taxRegime.maxAge` | With a unit, such as `45d`. Without it, `maxAge` applies. |
| `history` in `/simples` | `company.taxRegime.view=DETAILED` | |
| `states` in `/ccc` | `stateRegistry.states` | In Lookup CPF, the parameter is required and accepts `ALL` or state abbreviations, with no `ORIGIN`. |
| `maxAge` in `/ccc` | `stateRegistry.maxAge` | With a unit. |
| `source` in `/ccc` | No equivalent | v2 uses the CCC only. |
| `maxAge` in `/suframa` | `suframa.maxAge` | With a unit. |
| `pages` in `/rfb/certificate` | `certificates` | `REGISTRATION` becomes `RFB_REGISTRATION` and `MEMBERS` becomes `RFB_PARTNERS`. In v1 both pages were the default; in v2 `certificates` is required. |
| `state` in `/ccc/certificate` | No equivalent | A CNPJ's CCC certificate covers only the establishment's own UF; a CPF's covers a single UF with a known registration, which can't be chosen. |
| `type` in `/office/{taxId}/map` | `type` | Uppercase values: `roadmap` becomes `ROADMAP`, and likewise `TERRAIN`, `SATELLITE` and `HYBRID`. |
| `width`, `height`, `scale`, `zoom` and `fov` | No equivalent | v2 images are 640 by 640 pixels, with fixed size and zoom. |

### Search CNPJ

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `token` | `cursor` | Sent alone, with no other parameter. |
| `limit` | `limit` | `1` to `1000`, default `10`. |
| `names.in`, `names.nin` | `names.some`, `names.none` | Legal name or trade name. |
| `company.name.in`, `company.name.nin` | `company.legalName.some`, `company.legalName.none` | |
| `alias.in`, `alias.nin` | `tradeName.some`, `tradeName.none` | |
| `company.equity.gte`, `company.equity.lte` | `company.shareCapital.gte`, `company.shareCapital.lte` | |
| `company.nature.id.in`, `company.nature.id.nin` | `company.legalNature.code.in`, `company.legalNature.code.nin` | 4-character codes. |
| `company.size.id.in` | `company.size.code.in` | `1` becomes `MICRO`, `3` becomes `SMALL` and `5` becomes `OTHER`. |
| `company.simples.optant.eq=true` | `company.taxRegime.type.code.in=SIMPLES_NACIONAL,SIMPLES_NACIONAL_HYBRID,SIMPLES_NACIONAL_SIMEI` | |
| `company.simples.optant.eq=false` | `company.taxRegime.type.code.in` with the other regimes | `ACTUAL_PROFIT`, `PRESUMED_PROFIT`, `ARBITRATED_PROFIT` and `NOT_APPLICABLE`. |
| `company.simples.since.gte`, `company.simples.since.lte` | `company.taxRegime.simplesNacionalStartDate.gte`, `company.taxRegime.simplesNacionalStartDate.lte` | |
| `company.simei.optant.eq=true` | `company.taxRegime.type.code.in=SIMPLES_NACIONAL_SIMEI` | |
| `company.simei.optant.eq=false` | `company.taxRegime.type.code.in` with the other regimes | `ACTUAL_PROFIT`, `PRESUMED_PROFIT`, `ARBITRATED_PROFIT`, `SIMPLES_NACIONAL`, `SIMPLES_NACIONAL_HYBRID` and `NOT_APPLICABLE`. |
| `company.simei.since.gte`, `company.simei.since.lte` | `company.taxRegime.simeiStartDate.gte`, `company.taxRegime.simeiStartDate.lte` | |
| No equivalent | `company.taxRegime.regularIbsStartDate.gte`, `company.taxRegime.regularIbsStartDate.lte`, `company.taxRegime.regularCbsStartDate.gte`, `company.taxRegime.regularCbsStartDate.lte` | Start of the current period in the IBS and CBS regular regime. |
| `taxId.nin` | `lists.none` | List IDs. v2 also has `lists.some`, which restricts the search to the CNPJs in the lists. |
| `founded.gte`, `founded.lte` | `incorporationDate.gte`, `incorporationDate.lte` | |
| `head.eq=true` | `type.code.in=HEAD` | |
| `head.eq=false` | `type.code.in=BRANCH` | |
| `statusDate.gte`, `statusDate.lte` | `statusDate.gte`, `statusDate.lte` | |
| `status.id.in` | `status.code.in` | `1` becomes `VOID`, `2` becomes `ACTIVE`, `3` becomes `SUSPENDED`, `4` becomes `NONCOMPLIANT` and `8` becomes `CLOSED`. |
| `reason.id.in` | `statusReason.code.in` | 2-character string: `1` becomes `01`. |
| `specialDate.gte`, `specialDate.lte` | `specialStatusDate.gte`, `specialStatusDate.lte` | |
| `special.id.in` | `specialStatus.code.in` | 3-character string. |
| `address.street.in`, `address.street.nin` | `address.street.in`, `address.street.nin` | |
| `address.number.in`, `address.number.nin` | `address.number.in`, `address.number.nin` | |
| `address.details.in`, `address.details.nin` | `address.details.in`, `address.details.nin` | |
| `address.district.in`, `address.district.nin` | `address.district.in`, `address.district.nin` | |
| `address.municipality.in`, `address.municipality.nin` | `address.municipality.in`, `address.municipality.nin` | 7-digit IBGE code. |
| `address.state.in` | `address.state.in` | |
| `address.zip.in`, `address.zip.gte`, `address.zip.lte` | `address.postalCode.in`, `address.postalCode.gte`, `address.postalCode.lte` | 8-digit CEP. |
| `address.country.id.in`, `address.country.id.nin` | `address.country.code.in`, `address.country.code.nin` | Numeric M49 code in v1, 2-letter code in v2: `76` becomes `BR`. |
| `phones.ex=true` | `phones.gte=1` | |
| `phones.ex=false` | `phones.lte=0` | |
| `phones.type.in` | `phones.type.code.some` | `LANDLINE` or `MOBILE`. |
| `phones.area.in`, `phones.area.nin` | `phones.area.some`, `phones.area.none` | 2-digit area code (DDD). |
| `phones.area.gte`, `phones.area.lte` | No equivalent | List the area codes in `phones.area.some`. |
| `phones.number.in`, `phones.number.nin` | `phones.number.some`, `phones.number.none` | Number without the area code in v1, E.164 in v2, such as `+5511971564144`. |
| `emails.ex=true` | `emails.gte=1` | |
| `emails.ex=false` | `emails.lte=0` | |
| `emails.ownership.in` | `emails.type.code.some` | `ACCOUNTING` and `CORPORATE` stay, and `PERSONAL` becomes `CONSUMER`. In v1, `CORPORATE` included the emails v2 classifies as `ACADEMIC` and `GOVERNMENT`; send `CORPORATE,ACADEMIC,GOVERNMENT` to keep the same results. |
| `emails.address.in`, `emails.address.nin` | `emails.address.some`, `emails.address.none` | |
| `emails.domain.in`, `emails.domain.nin` | `emails.domain.some`, `emails.domain.none` | |
| `activities.id.in`, `activities.id.nin` | `economicActivities.code.some`, `economicActivities.code.none` | 7-digit CNAE: `111301` becomes `0111301`. |
| `mainActivity.id.in`, `mainActivity.id.nin` | `primaryActivity.code.in`, `primaryActivity.code.nin` | |
| `sideActivities.id.in`, `sideActivities.id.nin` | `secondaryActivities.code.some`, `secondaryActivities.code.none` | |
| No equivalent | `search` | Free text across CNPJ, names, phones, emails and address. |
| No equivalent | `sort`, `order` | `relevance`, `taxId`, `incorporationDate`, `company.shareCapital` or `company.legalName`, in `ASC` or `DESC` order. Without them, the order is the same as in v1. See [Sorting](https://cnpja.com/en-us/docs/api/reference#description/sorting). |

To combine `company.simples.optant.eq` and `company.simei.optant.eq`, send a single `company.taxRegime.type.code.in` with only the codes in both lists, such as `SIMPLES_NACIONAL,SIMPLES_NACIONAL_HYBRID` for Simples Nacional optants that aren't MEIs.

All filters are in [Search filters](https://cnpja.com/en-us/docs/api/reference#description/search-filters).

### Search people

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `token` | `cursor` | |
| `limit` | `limit` | |
| `type.in` | `type.code.in` | `LEGAL` becomes `ESTABLISHMENT`, `NATURAL` becomes `INDIVIDUAL`, `FOREIGN` becomes `FOREIGNER`. `UNKNOWN` is never returned by the search. |
| `name.in` | `search` or `legalName.in` | A full name goes in `legalName.in`, which compares the whole name; `search` requires every word. |
| `name.nin` | `legalName.nin` | |
| `taxId.in` | `taxId.in` | A CPF is still matched on its 4th to 9th digits. |
| `age.in` | `ageGroup.in` | Same values, such as `31-40`. |
| `country.id.in`, `country.id.nin` | `domicileCountry.code.in`, `domicileCountry.code.nin` | M49 code in v1, 2-letter code in v2. |
| No equivalent | `participations.gte`, `participations.lte` | Number of participations in companies. v1 returned only people with at least one participation; send `participations.gte=1` to keep that. |
| No equivalent | `sort`, `order` | `relevance`, `legalName` or `participations`. Without them, the order is the same as in v1. |

### Lists

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `title` | `name` | |
| `description` | No equivalent | |
| `items` in Create list | `items` | Required in v2, along with `type=ESTABLISHMENT`. |
| `query` and `limit` in Create list | No equivalent | v2 doesn't create lists from filters. Search with Search CNPJ and send the CNPJs in `items`. |
| `items` in Update list | `items` with `operation=REPLACE` | In v1, `items` replaced the list's CNPJs. v2 also accepts `ADD` and `REMOVE`. |
| `token`, `limit` and `search` in Search lists | `cursor`, `limit` and `search` | In v2, `search` looks at the name only. |
| No equivalent | `sort` and `order` in Search lists | `createdAt`, `updatedAt`, `name` or `size`. Without them, the order is the same as in v1. |

## Response fields

Paths with `[]` refer to each item of a list. The `company.taxRegime`, `stateRegistry`, `suframa` and `address.coordinates` fields appear only when the resource is requested in `expand`.

### Identification and status

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `taxId` | `taxId` | |
| `updated` | `updatedAt` | Last update from the Receita Federal. |
| `alias` | `tradeName` | |
| `founded` | `incorporationDate` | |
| `head` | `type.code` | `true` becomes `HEAD` and `false` becomes `BRANCH`. |
| `statusDate` | `statusDate` | |
| `status.id` | `status.code` | `1` becomes `VOID`, `2` becomes `ACTIVE`, `3` becomes `SUSPENDED`, `4` becomes `NONCOMPLIANT` and `8` becomes `CLOSED`. |
| `status.text` | `status.label` | |
| `reason.id` | `statusReason.code` | A number in v1, a 2-character string in v2, such as `01`. |
| `reason.text` | `statusReason.label` | |
| `specialDate` | `specialStatusDate` | |
| `special.id` | `specialStatus.code` | 3-character string. |
| `special.text` | `specialStatus.label` | |

### Address and contacts

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `address.street` | `address.street` | |
| `address.number` | `address.number` | |
| `address.details` | `address.details` | |
| `address.district` | `address.district` | |
| `address.city` | `address.city` | |
| `address.state` | `address.state` | |
| `address.zip` | `address.postalCode` | |
| `address.municipality` | `address.municipality` | A number in v1, a 7-digit string in v2. |
| `address.country.id` | `address.country.code` | M49 code in v1, 2-letter code in v2: `76` becomes `BR`. |
| `address.country.name` | `address.country.label` | |
| `address.latitude`, `address.longitude` | `address.coordinates.latitude`, `address.coordinates.longitude` | With `expand=address.coordinates`. `null` when the address can't be located. |
| `phones[].type` | `phones[].type.code` | |
| `phones[].area`, `phones[].number` | `phones[].number` | Area code and number become a single E.164 string: `11` and `971564144` become `+5511971564144`. |
| `emails[].address` | `emails[].address` | |
| `emails[].ownership` | `emails[].type.code` | v2 also distinguishes `ACADEMIC` and `GOVERNMENT`, which v1 returned as `CORPORATE`. |
| `emails[].domain` | No equivalent | Extract the domain from `emails[].address`. |

### Activities

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `mainActivity.id` | `primaryActivity.code` | A number in v1, a 7-digit string in v2. |
| `mainActivity.text` | `primaryActivity.label` | |
| `sideActivities[].id` | `secondaryActivities[].code` | 7-digit string. |
| `sideActivities[].text` | `secondaryActivities[].label` | |

### Company and partners

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `company.id` | `company.id` | CNPJ root, 8 characters. |
| `company.name` | `company.legalName` | |
| `company.equity` | `company.shareCapital` | |
| `company.nature.id` | `company.legalNature.code` | A number in v1, a 4-digit string in v2. |
| `company.nature.text` | `company.legalNature.label` | |
| `company.size.id` | `company.size.code` | `1` becomes `MICRO`, `3` becomes `SMALL` and `5` becomes `OTHER`. |
| `company.size.acronym` | No equivalent | Derive it from `company.size.code`. |
| `company.size.text` | `company.size.label` | |
| `company.jurisdiction` | `company.federativeEntity.label` | `company.federativeEntity.code` holds `BR` for the União, the UF abbreviation or the municipality's IBGE code. |
| `company.members[]` | `company.partners[]` | See [Partners and people](https://cnpja.com/en-us/docs/api/partners). |
| `company.members[].since` | `company.partners[].admissionDate` | |
| `company.members[].role.id` | `company.partners[].role.code` | 2-character string, such as `49`. |
| `company.members[].role.text` | `company.partners[].role.label` | |
| `company.members[].person.id` | `company.partners[].person.id` | Same ID, used in Lookup person. |
| `company.members[].person.type` | `company.partners[].person.type.code` | `LEGAL` becomes `ESTABLISHMENT`, `NATURAL` becomes `INDIVIDUAL`, `FOREIGN` becomes `FOREIGNER` and `UNKNOWN` stays. |
| `company.members[].person.name` | `company.partners[].person.legalName` | |
| `company.members[].person.taxId` | `company.partners[].person.taxId` | Masked CPF or CNPJ. Absent in v1, `null` in v2 for `FOREIGNER` and `UNKNOWN`. |
| `company.members[].person.age` | `company.partners[].person.ageGroup` | Same values, such as `31-40`. |
| `company.members[].person.country` | `company.partners[].person.domicileCountry` | 2-letter `code` and the country name in `label`. Only for `FOREIGN` in v1; always present in v2. |
| `company.members[].agent.person` | `company.partners[].legalRepresentative.person` | Same shape as `person`. |
| `company.members[].agent.role` | `company.partners[].legalRepresentative.role` | `code` and `label`. |

### Tax data

With `expand=company.taxRegime`:

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `company.simples.optant` | `company.taxRegime.type.code` | `true` matches `SIMPLES_NACIONAL`, `SIMPLES_NACIONAL_HYBRID` or `SIMPLES_NACIONAL_SIMEI`. The other values are `ACTUAL_PROFIT`, `PRESUMED_PROFIT`, `ARBITRATED_PROFIT` and `NOT_APPLICABLE`. |
| `company.simples.since` | `company.taxRegime.simplesNacionalStartDate` | Present only when `type.code` is `SIMPLES_NACIONAL`, `SIMPLES_NACIONAL_HYBRID` or `SIMPLES_NACIONAL_SIMEI`; v1 returned `null` in the other cases. |
| `company.simei.optant` | `company.taxRegime.type.code` | `true` matches `SIMPLES_NACIONAL_SIMEI`. |
| `company.simei.since` | `company.taxRegime.simeiStartDate` | Present only when `type.code` is `SIMPLES_NACIONAL_SIMEI`; v1 returned `null` in the other cases. |
| No equivalent | `company.taxRegime.regularIbsStartDate`, `company.taxRegime.regularCbsStartDate` | Start of the current period in the IBS and CBS regular regime. Present only with `company.taxRegime.view=DETAILED` and when `type.code` is `SIMPLES_NACIONAL_HYBRID`, which marks Simples Nacional optants that also opted into the IBS or CBS regular regime. Either can be `null`. |
| `company.simples.history[]` | `company.taxRegime.timeline[]` with `type.code` equal to `SIMPLES_NACIONAL_PERIOD` | With `company.taxRegime.view=DETAILED`. |
| `company.simei.history[]` | `company.taxRegime.timeline[]` with `type.code` equal to `SIMEI_PERIOD` | With `company.taxRegime.view=DETAILED`. The `timeline` also holds future events and periods under other regimes. |
| `history[].from` | `timeline[].startDate` | |
| `history[].until` | `timeline[].endDate` | |
| `history[].text` | `timeline[].details` | |

With `expand=stateRegistry`:

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `registrations[]` | `stateRegistry.registrations[]` | |
| `registrations[].number` | `stateRegistry.registrations[].number` | |
| `registrations[].state` | `stateRegistry.registrations[].state` | |
| `registrations[].statusDate` | `stateRegistry.registrations[].statusDate` | |
| `registrations[].enabled` | `stateRegistry.registrations[].isEnabled` | |
| `registrations[].status.id` | `stateRegistry.registrations[].hasRestriction` | `1`, no restriction, becomes `false`; `2`, blocked as recipient in the UF, becomes `true`. Interstate blocks are in `stateRegistry.taxRestrictions[]`. |
| `registrations[].type.id` | `stateRegistry.registrations[].type.code` | `1` becomes `STATE_TAXPAYER`, `2` becomes `TAX_SUBSTITUTION`, `3` becomes `NON_TAXPAYER`, `4` becomes `INTERSTATE_TAXPAYER` and `5` becomes `RURAL_PRODUCER`. |
| `registrations[].type.text` | `stateRegistry.registrations[].type.label` | |

With `expand=suframa`:

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `suframa[]` | `suframa.registrations[]` | |
| `suframa[].number` | `suframa.registrations[].number` | |
| `suframa[].since` | `suframa.registrations[].registrationDate` | |
| `suframa[].approved` | `suframa.registrations[].hasApprovedProject` | |
| `suframa[].approvalDate` | `suframa.registrations[].approvalDate` | |
| `suframa[].status.id` | `suframa.registrations[].status.code` | `1` becomes `ACTIVE`, `2` becomes `INACTIVE`, `3` becomes `BLOCKED` and `4` becomes `CANCELLED`. |
| `suframa[].status.text` | `suframa.registrations[].status.label` | |
| `suframa[].incentives[]` | [Mapa dos Incentivos Fiscais](https://www.gov.br/suframa/pt-br/zfm/mapa-dos-incentivos-fiscais-ultima-versao-28-09.xlsx) | SUFRAMA stopped publishing each registration's incentives in its public registry lookup and now points to this official spreadsheet, so v2 doesn't return them. The criteria SUFRAMA applied are in [Estimate incentives](https://cnpja.com/en-us/docs/data/suframa#incentives). |

### Standalone lookups

The `/rfb`, `/simples`, `/ccc` and `/suframa` responses use the fields above in a different layout. In v2, everything is in the Lookup CNPJ or Lookup CPF response:

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `/rfb`: `name`, `equity`, `nature`, `size`, `jurisdiction` | `company.legalName`, `company.shareCapital`, `company.legalNature`, `company.size`, `company.federativeEntity` | The other `/rfb` fields follow the tables above. |
| `/rfb`: `members[]` | `company.partners[]` | |
| `/simples`: `updated` | `company.taxRegime.updatedAt` | |
| `/simples`: `simples`, `simei` | `company.taxRegime` | As in the tax data table. |
| `/ccc`: `updated` | `stateRegistry.updatedAt` | |
| `/ccc`: `name` | `company.legalName` or, in Lookup CPF, `legalName` | |
| `/ccc`: `originState` | `address.state` | Lookup CNPJ only. |
| `/suframa`: `updated` | `suframa.registrations[].updatedAt` | v1 returned one registration; v2 returns all of them. |
| `/suframa`: `number`, `since`, `approved`, `approvalDate`, `status` | `suframa.registrations[]` | As in the `expand=suframa` table. |
| `/suframa`: `incentives` | [Mapa dos Incentivos Fiscais](https://www.gov.br/suframa/pt-br/zfm/mapa-dos-incentivos-fiscais-ultima-versao-28-09.xlsx) | Like `suframa[].incentives[]` in the `expand=suframa` table. |
| `/suframa`: `name` | `company.legalName` or, in Lookup CPF, `legalName` | |
| `/suframa`: `head` | `type.code` | Lookup CNPJ only. |
| `/suframa`: `nature` | `company.legalNature` | Lookup CNPJ only. |
| `/suframa`: `address`, `phones`, `emails` | `suframa.registrations[].address`, `suframa.registrations[].phones`, `suframa.registrations[].emails` | Same v2 address, phone and email formats. |
| `/suframa`: `mainActivity`, `sideActivities` | `suframa.registrations[].primaryActivity`, `suframa.registrations[].secondaryActivities` | |
| `/suframa`: `mainActivity.performed`, `sideActivities[].performed` | No equivalent | Always `true` in the source. |

### Company, person and CEP

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `/company`: `simples`, `simei` | `taxRegime` | Always present in Lookup company, without `regularIbsStartDate`, `regularCbsStartDate` and `timeline`. |
| `/company`: `members[]` | `partners[]` | |
| `/company`: `offices[]` | `establishments[]` | Same identification and status fields, renamed as in the tables above. v2 also brings `address` and `updatedAt`. |
| `/company`: `offices[].mainActivity` | `establishments[].primaryActivity` | |
| `/person`: `type`, `name`, `age`, `country` | `type.code`, `legalName`, `ageGroup`, `domicileCountry` | Same codes as partners. |
| `/person`: `membership[]` | `participations[]` | |
| `/person`: `membership[].since` | `participations[].admissionDate` | |
| `/person`: `membership[].role`, `membership[].agent` | `participations[].role`, `participations[].legalRepresentative` | |
| `/person`: `membership[].company` | `participations[].company` | `name` becomes `legalName`, `equity` becomes `shareCapital`, `nature` becomes `legalNature`, `size.id` becomes `size.code` and `jurisdiction` becomes `federativeEntity`. |
| `/zip`: `updated` | `updatedAt` | |
| `/zip`: `code`, `street`, `number`, `district`, `city`, `state` | `code`, `street`, `number`, `district`, `city`, `state` | |
| `/zip`: `municipality` | `municipality` | A number in v1, a 7-digit string in v2. |
| No equivalent | `type`, `status`, `name`, `details` | CEP type and status, and recipient data. See [CEP and addresses](https://cnpja.com/en-us/docs/api/postal-codes). |

### Lists and pagination

| CNPJá v1 | CNPJá v2 | Notes |
|---|---|---|
| `id` | `id` | Same ID. |
| `title` | `name` | |
| `created`, `updated` | `createdAt`, `updatedAt` | |
| `size` | `size` | |
| `description`, `query`, `limit` | No equivalent | |
| `items` in Lookup list | No equivalent | Lookup list doesn't return the CNPJs. Use Search CNPJ with `lists.some`. |
| No equivalent | `type` | Always `ESTABLISHMENT`. |
| `next` | `nextCursor` | `null` on the last page. |
| `count` | `total` | |
| `limit`, `records` | `limit`, `records` | |

### Formats

- Codes become strings: [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, status reason, special status and [IBGE code](https://www.ibge.gov.br/explica/codigos-dos-municipios.php) come as fixed-length strings with leading zeros, never as numbers.
- `id` and `text` become `code` and `label`. Use `code` in your logic; `label` is for display only, follows the response language and may change without notice.
- Countries drop the numeric M49 code and use the 2-letter code.
- Phones become a single E.164 string.
- A resource requested in `expand` is always present, even when empty, and a resource you don't request is absent. `null`, an empty list and a missing field mean different things.

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

## Behavior differences

### Freshness and caching

In v2, 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`. Optional resources accept a limit of their own, such as `stateRegistry.maxAge`. v1 certificates used data up to 1 day old; in Issue CNPJ dossier and Issue CPF dossier the default is `45d`, so send `maxAge=1d` to keep that behavior. 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).

### Resources with no record

In v1, `/suframa` answered `404` when the document had no SUFRAMA registration. In v2, in Lookup CNPJ, `expand=suframa` returns an empty `suframa.registrations`, and `expand=stateRegistry` with no registrations returns an empty `stateRegistry.registrations`. In Lookup CPF, a CPF with no registration in the queried sources returns `404` `INDIVIDUAL_NOT_FOUND`, as explained in [SUFRAMA](https://cnpja.com/en-us/docs/api/suframa).

### Errors

The v1 Reference doesn't document the error format. In v2, 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).

> **Important:** remove the v1 parameters that have no equivalent, such as `strategy`, `maxStale`, `sync`, `links` and `registrationsSource`. In v2, an unknown parameter is rejected with `400` in operations that take query parameters.

### Limits

Limits are the same in both versions. 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

v1 described usage in credits, with the balance at `/credit` and the cost in the `cnpja-request-cost` header. 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). 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).

### Pagination

Send each page's `nextCursor` as `cursor`, on its own, without repeating filters or `limit`, until `nextCursor` comes back `null`. The cursor keeps the filters, `sort`, `order` and `limit` of the first request and is valid for a set time between one page and the next, given in [Timeout and size](https://cnpja.com/en-us/docs/api/limits-and-errors#timeout-and-size); once expired, the response is `400` `PAGE_CURSOR_INVALID`, and the client must send the first request again to get a new cursor. See [Pagination](https://cnpja.com/en-us/docs/api/reference#description/pagination).

### Search terms

In v1, words separated by spaces had to appear together in the same establishment or person, and comma-separated terms were alternatives. In v2, `some` and `none` treat each word separately, and `search` requires every word, in any order. See [CNPJ search and lists](https://cnpja.com/en-us/docs/api/cnpj-search).

### Public access

As in v1, Lookup CNPJ and Lookup CEP accept requests without a key, as long as the URL has no query parameters at all; any parameter results in `401` `API_KEY_MISSING`. These requests use the default values, such as `maxAge=45d` with no `expand`, are not billed and follow limits of their own, counted per source IP. See [Public access](https://cnpja.com/en-us/docs/api/public-access).

### 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

- The credit balance (`/credit`) and the `cnpja-request-cost` header.
- List exports (`/list/{listId}/export`), already deprecated in v1.
- Public file links (`links`).
- `strategy=CACHE`, `maxStale`, `sync`, `registrationsSource` and `source`.
- Image size, scale, zoom and field of view.
- The company size acronym (`size.acronym`) and the email domain (`emails[].domain`).
- State registration statuses `3` and `10` and type `9`, and SUFRAMA status `5`.
- List description, creation filters (`query`) and limit (`limit`), and reading the CNPJs in Lookup list.
- Area code ranges (`phones.area.gte` and `phones.area.lte`) in the CNPJ search.

## Step by step

1. List your integration's v1 calls and find each one's equivalent in the matching operations table.
2. Keep the key and the `Authorization` header; switch the path to `https://api.cnpja.com/v2` and the new names.
3. Merge the standalone lookups made for the same CNPJ into a single Lookup CNPJ call, requesting the resources in `expand`.
4. Rewrite the parameters: add the unit to `maxAge`, replace the booleans with `expand` and remove the parameters with no equivalent.
5. Rewrite the field parsing with the tables above, converting numeric codes into `code` and phones into E.164.
6. Switch pagination to `cursor` and `nextCursor`, and error handling to `code`, with `206` treated as success.
7. Validate: with a key, compare both versions' responses for a few CNPJs and check usage under [Requests](https://cnpja.com/en-us/organizations/current/usage-events).
8. Switch traffic and watch errors and usage over the first few days.
