Skip to content
Migrate from CNPJá v0 to v2
API · Migration

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_case 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 /companies/37335118000180 to GET /v2/establishments/37335118000180, on the same host and with the same API key.
  • The *_max_age parameters, in days, become maxAge and each resource’s own limit, with an explicit unit such as 45d.
  • simples_max_age and sintegra_max_age no longer switch resources on: in v2, each one is requested in expand.
  • Fields move to camelCase and change place: company data sits under company and the registration status moves up to the response root.
  • Classified values become objects with code and label, and the codes move to English: MATRIZ becomes HEAD, ATIVA becomes ACTIVE.
  • The files and maps links 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 Authorization header, with no prefix: Authorization: YOUR_API_KEY. With Bearer, the request is rejected with 401 API_KEY_INVALID. See Authentication.
  • Base URL: https://api.cnpja.com/v2. v0 answers on the same host, without the version prefix.
  • 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á v0CNPJá v2Notes
GET /companies/37335118000180Lookup CNPJSame 14-character CNPJ in the path. See CNPJ lookup.
files.registration linkIssue CNPJ dossiercertificates=RFB_REGISTRATION. See Certificates.
files.membership linkIssue CNPJ dossiercertificates=RFB_PARTNERS. Both can come in the same PDF: certificates=RFB_REGISTRATION,RFB_PARTNERS.
maps.roads and maps.satellite linksRender CNPJ maptype=ROADMAP or type=SATELLITE. See Location and maps.
maps.street linkRender CNPJ street viewNo parameters.

Important: don’t just add the version prefix. In v2, /v2/companies/ is Lookup company, which takes only the 8-character CNPJ root. The match for the v0 lookup is /v2/establishments/, with the full CNPJ.

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á v0CNPJá v2Notes
taxId (path)taxId (path)14-character CNPJ, no punctuation.
company_max_agemaxAgeAn integer in days in v0, text with a unit in v2: company_max_age=45 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_max_ageexpand=company.taxRegime and company.taxRegime.maxAgeIn v0, sending the parameter added the regime. In v2, request the resource in expand and, for a limit of its own, send company.taxRegime.maxAge, such as 1d. Without it, maxAge applies.
sintegra_max_ageexpand=stateRegistry, stateRegistry.states=ALL and stateRegistry.maxAgev0 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_cache_fallbackNo equivalentAlready 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á v0CNPJá v2Notes
last_updateupdatedAtLast update from the Receita Federal.
tax_idtaxId
namecompany.legalNameLegal name.
aliastradeNameTrade name, null when there is none.
typetype.codeMATRIZ becomes HEAD and FILIAL becomes BRANCH.
foundedincorporationDateOpening date.
registration.statusstatus.codeSee the code table below.
registration.status_datestatusDate
registration.status_reasonstatusReason.labelv2 also returns the official code in statusReason.code, such as 01.
registration.special_statusspecialStatus.labelv2 also returns the code in specialStatus.code, such as 418.
registration.special_status_datespecialStatusDate
registration.status (v0)status.code (v2)
ATIVAACTIVE
BAIXADACLOSED
INAPTANONCOMPLIANT
SUSPENSASUSPENDED
NULAVOID

Address and contacts

CNPJá v0CNPJá v2Notes
address.streetaddress.street
address.numberaddress.number
address.detailsaddress.details
address.neighborhoodaddress.district
address.cityaddress.city
address.city_ibgeaddress.municipality7-digit IBGE municipality code.
address.stateaddress.stateUF abbreviation.
address.state_ibgeNo equivalentUse the first 2 digits of address.municipality.
address.zipaddress.postalCode8-digit CEP.
emailemails[0].addressv2 returns every email, each with its type in emails[].type.
phonephones[0].numberIn v2 the number comes in international format: 11971564144 becomes +5511971564144. Each phone has its type in phones[].type.
phone_altphones[1].numberSame format as phones[0].number.

Activities

CNPJá v0CNPJá v2Notes
primary_activity.codeprimaryActivity.code7-digit CNAE.
primary_activity.descriptionprimaryActivity.label
secondary_activities[].codesecondaryActivities[].code
secondary_activities[].descriptionsecondaryActivities[].label

Company and partners

CNPJá v0CNPJá v2Notes
capitalcompany.shareCapital
sizecompany.size.codeME becomes MICRO, EPP becomes SMALL and DEMAIS becomes OTHER.
legal_nature.codecompany.legalNature.code
legal_nature.descriptioncompany.legalNature.label
federal_entitycompany.federativeEntity.labelv2 also returns company.federativeEntity.code: BR for the Union, the UF abbreviation or the IBGE municipality code.
membership[]company.partners[]Board of partners and administrators.
membership[].namecompany.partners[].person.legalName
membership[].tax_idcompany.partners[].person.taxIdMasked CPF, such as ***650245**, or CNPJ. null for foreigners and unknown persons.
membership[].home_countrycompany.partners[].person.domicileCountryv0 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[].role.codecompany.partners[].role.code
membership[].role.descriptioncompany.partners[].role.label
membership[].legal_repcompany.partners[].legalRepresentativeLegal representative. Its inner fields follow the same mapping: name becomes person.legalName, tax_id becomes person.taxId, home_country becomes person.domicileCountry and role stays role.

In v2, each partner also has a stable ID in person.id, the person type in person.type, the age group in person.ageGroup and the date they joined in admissionDate. See Partners and people.

Simples Nacional and SIMEI

Present only with company.taxRegime in expand. See Tax regime.

CNPJá v0CNPJá v2Notes
simples_nacional.last_updatecompany.taxRegime.updatedAt
simples_nacional.simples_optantcompany.taxRegime.type.codeAn optant when the code is SIMPLES_NACIONAL, SIMPLES_NACIONAL_HYBRID or SIMPLES_NACIONAL_SIMEI. Otherwise v2 states the regime, such as PRESUMED_PROFIT.
simples_nacional.simples_includedcompany.taxRegime.simplesNacionalStartDateStart of the current period. Present only when the code is SIMPLES_NACIONAL, SIMPLES_NACIONAL_HYBRID or SIMPLES_NACIONAL_SIMEI.
simples_nacional.simples_excludedcompany.taxRegime.timeline[].endDatev0 had already stopped filling this field. In v2, past periods come with company.taxRegime.view=DETAILED, in the timeline items whose type.code is SIMPLES_NACIONAL_PERIOD.
simples_nacional.simei_optantcompany.taxRegime.type.codeAn optant when the code is SIMPLES_NACIONAL_SIMEI. v2 also returns the period start in company.taxRegime.simeiStartDate.

In v2, Simples Nacional optants that also opted into the IBS or CBS regular regime have the code SIMPLES_NACIONAL_HYBRID. With company.taxRegime.view=DETAILED, company.taxRegime.regularIbsStartDate and company.taxRegime.regularCbsStartDate 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á v0CNPJá v2Notes
sintegra.last_updatestateRegistry.updatedAt
sintegra.home_state_registrationstateRegistry.registrations[].numberNo field of its own: use the registration whose state equals address.state.
sintegra.registrations[].numberstateRegistry.registrations[].number
sintegra.registrations[].statestateRegistry.registrations[].state
sintegra.registrations[].enabledstateRegistry.registrations[].isEnabled

v2 registrations also include the type, the status date and restrictions as a recipient, and interstate restrictions come in stateRegistry.taxRestrictions.

Files and maps

CNPJá v0CNPJá v2Notes
files.registrationNo fieldUse Issue CNPJ dossier with certificates=RFB_REGISTRATION.
files.membershipNo fieldUse Issue CNPJ dossier with certificates=RFB_PARTNERS.
maps.roadsNo fieldUse Render CNPJ map with type=ROADMAP.
maps.satelliteNo fieldUse Render CNPJ map with type=SATELLITE.
maps.streetNo fieldUse 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_VALIDATION_FAILED. 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_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.

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_cache_fallback: falling back to the cache on failures is always on.
  • address.state_ibge: derive it from the first 2 digits of address.municipality.
  • sintegra.home_state_registration: filter stateRegistry.registrations by the UF in address.state, or request stateRegistry.states=ORIGIN.
  • Links in files and maps: the response carries no URLs; call the file’s operation when you need it.
  • Uppercase country name in home_country: use person.domicileCountry.code or .label.

Step by step

  1. Confirm the API key used in v0 under API keys.
  2. Replace the /companies/ path with /v2/establishments/, keeping the same CNPJ.
  3. Convert company_max_age into maxAge, and simples_max_age and sintegra_max_age into expand values with their own limits.
  4. Choose the UFs for state registrations: ALL to keep the v0 behavior, or only the ones you need.
  5. Update how you read fields following the tables above, including the new codes for type, size and status.
  6. Replace the files and maps links with calls to Issue CNPJ dossier, Render CNPJ map and Render CNPJ street view, if you used them.
  7. Treat 206 as success and base error handling on code.
  8. Test with a few CNPJs using your key and compare with the v0 responses.
  9. Switch traffic to v2 and track consumption under Usage.

Informational content that may change without notice. It is not tax, accounting or legal advice, and CNPJá's terms and policies prevail over this page.