API FAQ
Frequently asked questions about the CNPJá API: keyless use, authentication, maxAge and other parameters, response fields, 402 and 429 errors and the trace ID.
Short answers to the questions of those who integrate through the API, each with a link to the page that covers the subject. Questions about data, tax data, freshness, usage and billing, which also apply to the platform, are in Frequently asked questions.
Access and authentication
Can the API be used without a key?
Yes, through public access: Lookup CNPJ and Lookup CEP accept requests with no key and no query parameters, which are not charged and have per-IP usage limits. Public access is a free courtesy, limited and revocable at any time, with no service level. The rules are in Public API access, no key.
Why does an existing CNPJ return 404 without a key?
Without a key, Lookup CNPJ does not query the Receita Federal for a CNPJ that is not in cached data yet, such as a CNPJ opened after the latest open data release, and responds 404 ESTABLISHMENT_. With a key, the same CNPJ is queried live; see CNPJs outside cached data.
Why is a keyless request with a query parameter rejected?
A request is public only when its URL has no query parameters at all. Any parameter, even a ?utm_ added by another tool, makes the request get 401 API_, and the error message names the parameter. Remove the parameter or send a key; see Request.
Why is the Bearer prefix rejected?
The whole Authorization header value is treated as the key, with no authentication scheme, so Bearer YOUR_ gets 401 API_. Send the key alone, with no prefix; see Sending the key.
Can I use the key in web pages or mobile apps?
No. Any user can extract a key embedded in a web page or an app and use it to consume the organization’s quota. Keep the key on the server, call the API from the backend and hand the frontend only the data it needs; see Best practices.
What should I do when a key is lost or leaked?
The full key is shown only once and cannot be retrieved: if it is lost, create another one and revoke the old one. If it leaked, revoke it immediately; otherwise, create the new key and update the application before revoking the old one. See Rotation and revocation without downtime.
Do request limits apply per key?
No. The requests-per-second and concurrent-request limits apply to the whole organization and add up all of its keys, just like the quota, and they grow with its plan. Creating more keys raises neither, but it keeps applications apart; see Usage limits.
Parameters and responses
How do I list all branches of a company in the API?
Send the CNPJ root, its first 8 characters, to Lookup company, which returns a summary of each establishment in establishments. For a branch’s phones, e-mails and activities, look up its taxId on Lookup CNPJ; see CNPJ lookup in the API.
Why does Lookup company return 404 for a newly opened company?
Lookup company delivers cached data only, so a root that is not in it yet gets 404 COMPANY_. Look up one of the company’s CNPJs on Lookup CNPJ, with a key, which adds the company to cached data, and retry the request; see CNPJ lookup in the API.
How do I send an alphanumeric CNPJ?
Under the same rules as a numeric one: 14 characters, and 8 for the root, with no punctuation and with uppercase letters. A CNPJ or a root out of format, lowercase letters included, gets 400, with no charge. Store CNPJs as text, never as numbers; see Alphanumeric CNPJ.
How do I request data newer than 45 days?
Send a smaller maxAge with an API key, such as maxAge=1d: each resource older than that goes through a live query at the source, at a higher cost. Keyless requests always use the 45d default; see Max age and partial success.
How do I require fresher data for a single resource?
Use the resource’s own max age, which replaces maxAge for that resource only: company., stateRegistry. or suframa.. With expand=stateRegistry&stateRegistry., for example, the CNPJ record keeps the 45-day default and state registrations are queried live if they are older than 1 day. Each resource max age is accepted only with the resource in expand; see Max age and partial success.
How can a limit in months be expressed in maxAge?
maxAge has no month unit: it accepts y (years), w (weeks), d (days), h (hours) and m (minutes), always lowercase, from 5m to 1y. For about three months, send 90d, since 3m means three minutes and gets 400 REQUEST_ for being below the minimum; see Max age and partial success.
How can I tell when a piece of data was updated?
Each resource reports its own last update in an updatedAt field, in UTC, such as company. and stateRegistry.. Compare it with the requested age to know whether the resource came within it; a resource with no updatedAt has never been queried. See Max age and partial success.
What does status 206 mean?
It is a partial success: a live query failed or timed out, and the affected resource came with its cached data, or empty if it was never queried, without being charged. Treat 206 as success and compare each resource’s updatedAt to find which one may be outdated; see Partial success.
Why doesn’t a smaller maxAge update actual, presumed or arbitrated profit?
The declared regime comes from ECF disclosures, which have no live query. A smaller maxAge or company. updates only the option for the Simples Nacional, for SIMEI and for the IBS and CBS regular regime; see Tax regime in the API.
Which codes identify an MEI and a Simples Nacional hybrid company?
In company., an MEI has SIMPLES_, a Simples Nacional hybrid company has SIMPLES_, and other Simples Nacional optants have SIMPLES_. Use type., not simeiStartDate, which can be null even for an MEI, and keep in mind that the regime may be estimated. The matching search filters are in Tax regime in the API.
How do I request state registrations from other states?
On Lookup CNPJ, stateRegistry. defaults to ORIGIN, the state of the establishment’s address. Send the state abbreviations, such as ORIGIN,MG, or ALL for every state, and request only the ones that matter, because with stateRegistry. each requested state is charged separately, as All states: mind the cost warns. The parameters are in State registrations in the API.
Why doesn’t Lookup CPF return Receita Federal CPF data?
That data is not part of the API. Lookup CPF returns only state registrations, from the CCC, and SUFRAMA registrations, so a 404 INDIVIDUAL_ means that no registration was found in the sources and states queried, or that the source failed on the CPF’s first lookup, not that the CPF does not exist; see Individuals with a registration.
How do I search for a person by masked CPF?
The CPF of individual partners comes masked, with only the fourth to ninth digits visible, so on Search people it also matches other people with the same visible digits. To narrow the result, send the CPF and the name in the same search. A masked CPF cannot be used on Lookup CPF, as Masked CPF explains; the parameters are in Partners and people in the API.
How do I find a person’s companies in the API?
Each partner is a person with its own id, a stable UUID that is neither the CPF nor the CNPJ. With the id, read from company. or from Search people, Lookup person returns the current participations in participations; see Partners and people in the API.
Why are an address’s coordinates null?
address. returns latitude and longitude equal to null when the registered address cannot be located, which happens with incomplete or outdated addresses, and a 206 can also return them null when the calculation fails. Each new request that asks for address. for that address repeats the calculation and is charged according to the metering rules. Coordinate precision is covered in Precision.
Why does a CEP return 400 or 404?
Always send all 8 digits, with no hyphen and with leading zeros, as in 01452922. A value that is not exactly 8 digits, such as 01310-100, gets 400 without charge, and an 8-digit CEP that is not found gets 404 POSTAL_, charged when the request has a key; see CEPs and addresses in the API.
How do I leave deactivated CEPs out of Search CEP?
Send status.. A deactivated CEP has status. equal to DEACTIVATED, is always of type LOCALITY, carries only city, state and municipality and is also returned by Lookup CEP; see CEPs and addresses in the API and, for the concept, CEPs, streets and IBGE codes.
How can search results be counted?
Every search response carries total, the number of records that match the filters across all pages. Send limit=1 to read the total with the lowest consumption; a search with no matches returns 200 with empty records and total equal to 0, never 404. See CNPJ search and lists in the API.
How do I search only the CNPJs of a list?
On Search CNPJ, send the list id in lists. to search only its CNPJs, or in lists. to leave them out. Lists are created with Create list; see CNPJ search and lists in the API.
How do I get labels in English?
Send Accept-Language: en-US exactly as written, since tags without a region, such as en, are ignored and the response stays in the pt-BR default. The language changes only label fields and error messages, never codes or source data, so application logic must use code; see Response format.
Limits and errors
What does status 429 mean?
The organization went over the requests-per-second limit (RATE_) or the concurrent-request limit (CONCURRENCY_), across all of its keys; without a key, the limit belongs to the IP address. The rejected request is not charged and can be retried after a short wait, but responses carry no Retry-After; see Limit exceeded.
What does status 402 mean?
The organization’s quota or overage budget is used up, and the code tells which: CACHED_, LIVE_ or OVERAGE_, described in Error codes. The request is not charged, but retrying does not help until the quota or the overage budget is raised, or the quota renews; see the ways out in Quota used up.
What timeout should the HTTP client use?
Above 60 seconds, the current maximum duration of a request in the API. Past that, the API responds 504 REQUEST_, and a client with a shorter timeout closes the connection first and loses the traceId; see Timeout and size.
Which errors can be retried without changes?
Errors 429, 500 and 504 are usually temporary, are not charged and can be retried with increasing intervals. A 400 or 401 requires fixing the request, a 402 persists until the quota or the overage budget is raised, or the quota renews, and a repeated 404 can be charged again; see Retries.
How do I identify a request when contacting you?
Every response, successful ones included, carries the trace-id header, and error responses repeat the value in the traceId field. Keep it in the application logs and send it with your request for help; see Trace ID and support.
Other questions
Do the platform and the API use the same data?
Yes, and the same quota too: every API key and every member using the app spends from the organization’s quota, as explained in The quota belongs to the organization. Each operation page of these docs points to the matching screen in the app, in its In the app section.
Where is the full technical specification?
In the Reference, with every operation, parameter, field and response. The pages of these docs explain how to use each operation and point to the Reference.
How do I migrate from another API to CNPJá’s?
The Migration guides, in the API sidebar, compare another API’s operations, parameters and fields with those of v2, such as Migrate from CNPJá v1 to v2.