Migrate from CNPJá v0 to v2
How to replace the CNPJá API v0 CNPJ lookup with v2, using the same key: new path, per-resource maxAge, camelCase fields and English codes.
API v0 has a single operation, the lookup of one CNPJ with snake_ fields. In v2 it matches Lookup CNPJ, which returns the same data under other names and codes, plus resources v0 didn’t have.
Overview
- The request changes from
GET /tocompanies/ 37335118000180 GET /, on the same host and with the same API key.v2/ establishments/ 37335118000180 - The
*_parameters, in days, becomemax_ age maxAgeand each resource’s own limit, with an explicit unit such as45d. simples_andmax_ age sintegra_no longer switch resources on: in v2, each one is requested inmax_ age expand.- Fields move to
camelCaseand change place: company data sits undercompanyand the registration status moves up to the response root. - Classified values become objects with
codeandlabel, and the codes move to English:MATRIZbecomesHEAD,ATIVAbecomesACTIVE. - The
filesandmapslinks leave the response: certificates, maps and street view are operations of their own that return the file.
Effort: low. It is a single operation, and most of the work is renaming fields and translating codes.
Prerequisites
- Account and key: v0 and v2 use the same API keys, from the same organization. If you don’t have one yet, see First request.
- Authentication: send the key as the entire value of the
Authorizationheader, with no prefix:Authorization: YOUR_. WithAPI_ KEY Bearer, the request is rejected with401API_. See Authentication.KEY_ INVALID - Base URL:
https:/. v0 answers on the same host, without the version prefix./ api. cnpja. com/ v2 - What carries over: keys, organization, plan quotas and request limits. Both versions draw from the same quotas, and an equivalent lookup consumes the same in v0 and v2.
- What changes: the path, the parameters, the response shape and the codes of classified values.
Matching operations
| CNPJá v0 | CNPJá v2 | Notes |
|---|---|---|
GET / | Lookup CNPJ | Same 14-character CNPJ in the path. See CNPJ lookup. |
files. link | Issue CNPJ dossier | certificates=RFB_. See Certificates. |
files. link | Issue CNPJ dossier | certificates=RFB_. Both can come in the same PDF: certificates=RFB_. |
maps. and maps. links | Render CNPJ map | type=ROADMAP or type=SATELLITE. See Location and maps. |
maps. link | Render CNPJ street view | No parameters. |
Important: don’t just add the version prefix. In v2,
/v2/is Lookup company, which takes only the 8-character CNPJ root. The match for the v0 lookup iscompanies/ /v2/, with the full CNPJ.establishments/
Request example
CNPJá v0:
GET /companies/37335118000180?simples_max_age=1&sintegra_max_age=1 HTTP/1.1
Host: api.cnpja.com
Authorization: YOUR_API_KEY CNPJá v2:
GET /v2/establishments/37335118000180?expand=company.taxRegime,stateRegistry&company.taxRegime.maxAge=1d&stateRegistry.maxAge=1d&stateRegistry.states=ALL HTTP/1.1
Host: api.cnpja.com
Authorization: YOUR_API_KEY Parameters
| CNPJá v0 | CNPJá v2 | Notes |
|---|---|---|
taxId (path) | taxId (path) | 14-character CNPJ, no punctuation. |
company_ | maxAge | An integer in days in v0, text with a unit in v2: company_ becomes maxAge=45d. The default is still 45 days. v2 accepts 5m to 1y, so 0 becomes 5m and values above one year become 1y. |
simples_ | expand=company. and company. | In v0, sending the parameter added the regime. In v2, request the resource in expand and, for a limit of its own, send company., such as 1d. Without it, maxAge applies. |
sintegra_ | expand=stateRegistry, stateRegistry. and stateRegistry. | v0 returned registrations in every UF. In v2 the default is only the establishment’s UF (ORIGIN); send ALL to keep the old behavior, or only the UFs you use. |
enable_ | No equivalent | Already deprecated in v0. In v2, falling back to the cache when a live query fails is always on, with a 206 response. |
All three v0 parameters are in days, so N becomes Nd, within the same 5m to 1y range. maxAge units: y years, w weeks, d days, h hours and m minutes, not months. The rules are in Max age and partial success.
Response fields
The v2 paths are relative to the Lookup CNPJ response. Date (YYYY-MM-DD), date-time (ISO 8601 in UTC) and amount (number) formats don’t change.
Identification and status
| CNPJá v0 | CNPJá v2 | Notes |
|---|---|---|
last_ | updatedAt | Last update from the Receita Federal. |
tax_ | taxId | |
name | company. | Legal name. |
alias | tradeName | Trade name, null when there is none. |
type | type. | MATRIZ becomes HEAD and FILIAL becomes BRANCH. |
founded | incorporationDate | Opening date. |
registration. | status. | See the code table below. |
registration. | statusDate | |
registration. | statusReason. | v2 also returns the official code in statusReason., such as 01. |
registration. | specialStatus. | v2 also returns the code in specialStatus., such as 418. |
registration. | specialStatusDate |
registration. (v0) | status. (v2) |
|---|---|
ATIVA | ACTIVE |
BAIXADA | CLOSED |
INAPTA | NONCOMPLIANT |
SUSPENSA | SUSPENDED |
NULA | VOID |
Address and contacts
| CNPJá v0 | CNPJá v2 | Notes |
|---|---|---|
address. | address. | |
address. | address. | |
address. | address. | |
address. | address. | |
address. | address. | |
address. | address. | 7-digit IBGE municipality code. |
address. | address. | UF abbreviation. |
address. | No equivalent | Use the first 2 digits of address.. |
address. | address. | 8-digit CEP. |
email | emails[0]. | v2 returns every email, each with its type in emails[].. |
phone | phones[0]. | In v2 the number comes in international format: 11971564144 becomes +5511971564144. Each phone has its type in phones[].. |
phone_ | phones[1]. | Same format as phones[0].. |
Activities
| CNPJá v0 | CNPJá v2 | Notes |
|---|---|---|
primary_ | primaryActivity. | 7-digit CNAE. |
primary_ | primaryActivity. | |
secondary_ | secondaryActivities[]. | |
secondary_ | secondaryActivities[]. |
Company and partners
| CNPJá v0 | CNPJá v2 | Notes |
|---|---|---|
capital | company. | |
size | company. | ME becomes MICRO, EPP becomes SMALL and DEMAIS becomes OTHER. |
legal_ | company. | |
legal_ | company. | |
federal_ | company. | v2 also returns company.: BR for the Union, the UF abbreviation or the IBGE municipality code. |
membership[] | company. | Board of partners and administrators. |
membership[]. | company. | |
membership[]. | company. | Masked CPF, such as ***650245**, or CNPJ. null for foreigners and unknown persons. |
membership[]. | company. | v0 returned the country name in uppercase, such as BRASIL. v2 returns the alpha-2 code in code (BR) and the name in label (Brasil). |
membership[]. | company. | |
membership[]. | company. | |
membership[]. | company. | Legal representative. Its inner fields follow the same mapping: name becomes person., tax_ becomes person., home_ becomes person. and role stays role. |
In v2, each partner also has a stable ID in person., the person type in person., the age group in person. and the date they joined in admissionDate. See Partners and people.
Simples Nacional and SIMEI
Present only with company. in expand. See Tax regime.
| CNPJá v0 | CNPJá v2 | Notes |
|---|---|---|
simples_ | company. | |
simples_ | company. | An optant when the code is SIMPLES_, SIMPLES_ or SIMPLES_. Otherwise v2 states the regime, such as PRESUMED_. |
simples_ | company. | Start of the current period. Present only when the code is SIMPLES_, SIMPLES_ or SIMPLES_. |
simples_ | company. | v0 had already stopped filling this field. In v2, past periods come with company., in the timeline items whose type. is SIMPLES_. |
simples_ | company. | An optant when the code is SIMPLES_. v2 also returns the period start in company.. |
In v2, Simples Nacional optants that also opted into the IBS or CBS regular regime have the code SIMPLES_. With company., company. and company. hold the start of their current period in each regular regime, and either can be null.
State registrations
Present only with stateRegistry in expand. See State registrations.
| CNPJá v0 | CNPJá v2 | Notes |
|---|---|---|
sintegra. | stateRegistry. | |
sintegra. | stateRegistry. | No field of its own: use the registration whose state equals address.. |
sintegra. | stateRegistry. | |
sintegra. | stateRegistry. | |
sintegra. | stateRegistry. |
v2 registrations also include the type, the status date and restrictions as a recipient, and interstate restrictions come in stateRegistry..
Files and maps
| CNPJá v0 | CNPJá v2 | Notes |
|---|---|---|
files. | No field | Use Issue CNPJ dossier with certificates=RFB_. |
files. | No field | Use Issue CNPJ dossier with certificates=RFB_. |
maps. | No field | Use Render CNPJ map with type=ROADMAP. |
maps. | No field | Use Render CNPJ map with type=SATELLITE. |
maps. | No field | Use Render CNPJ street view. |
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. Outdated registration data, tax regime and state registrations are queried in parallel. See Max age and partial success.
Partial success
When a live query fails or runs past its time limit, 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.
Errors
New for v0 users: a maxAge in the wrong format, or a resource parameter without its resource in expand, is rejected with 400 REQUEST_. 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.
Limits
Request limits apply across all operations, v0 included. 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. 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.
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, 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; 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. In Lookup CNPJ, registration data and each resource requested in expand count separately. Certificates, maps and street view are billed when you call each one’s operation. Responses carry no cost headers: track usage under Usage. See Queries and quota, what each operation consumes in the Metering Rules and Pricing.
Public access
v0 requires a key. In v2, 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_. 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.
Language and labels
v2 codes are fixed and in English, and the text goes in label. 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.
No equivalent
enable_: falling back to the cache on failures is always on.cache_ fallback address.: derive it from the first 2 digits ofstate_ ibge address..municipality sintegra.: filterhome_ state_ registration stateRegistry.by the UF inregistrations address., or requeststate stateRegistry..states=ORIGIN - Links in
filesandmaps: the response carries no URLs; call the file’s operation when you need it. - Uppercase country name in
home_: usecountry person.ordomicileCountry. code .label.
Step by step
- Confirm the API key used in v0 under API keys.
- Replace the
/companies/path with/v2/, keeping the same CNPJ.establishments/ - Convert
company_intomax_ age maxAge, andsimples_andmax_ age sintegra_intomax_ age expandvalues with their own limits. - Choose the UFs for state registrations:
ALLto keep the v0 behavior, or only the ones you need. - Update how you read fields following the tables above, including the new codes for type, size and status.
- Replace the
filesandmapslinks with calls to Issue CNPJ dossier, Render CNPJ map and Render CNPJ street view, if you used them. - Treat
206as success and base error handling oncode. - Test with a few CNPJs using your key and compare with the v0 responses.
- Switch traffic to v2 and track consumption under Usage.