# 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](https://cnpja.com/en-us/docs/faq).

## 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](https://cnpja.com/en-us/docs/api/public-access).

### 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_NOT_FOUND`. With a key, the same CNPJ is queried live; see [CNPJs outside cached data](https://cnpja.com/en-us/docs/api/public-access#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_source=site` added by another tool, makes the request get `401` `API_KEY_MISSING`, and the error `message` names the parameter. Remove the parameter or send a key; see [Request](https://cnpja.com/en-us/docs/api/public-access#request).

### Why is the Bearer prefix rejected?

The whole `Authorization` header value is treated as the key, with no authentication scheme, so `Bearer YOUR_API_KEY` gets `401` `API_KEY_INVALID`. Send the key alone, with no prefix; see [Sending the key](https://cnpja.com/en-us/docs/api/authentication#header).

### 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](https://cnpja.com/en-us/docs/api/authentication#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](https://cnpja.com/en-us/docs/api/authentication#rotation).

### 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](https://cnpja.com/en-us/docs/api/limits-and-errors#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](https://cnpja.com/en-us/docs/api/reference#tag/companies/GET/v2/companies/%7bid%7d), 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](https://cnpja.com/en-us/docs/api/cnpj-lookup).

### 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_NOT_FOUND`. 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](https://cnpja.com/en-us/docs/api/cnpj-lookup).

### 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](https://cnpja.com/en-us/docs/data/alphanumeric-cnpj#api).

### 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](https://cnpja.com/en-us/docs/api/max-age).

### 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.taxRegime.maxAge`, `stateRegistry.maxAge` or `suframa.maxAge`. With `expand=stateRegistry&stateRegistry.maxAge=1d`, 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](https://cnpja.com/en-us/docs/api/max-age).

### 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_VALIDATION_FAILED` for being below the minimum; see [Max age and partial success](https://cnpja.com/en-us/docs/api/max-age).

### How can I tell when a piece of data was updated?

Each [resource](https://cnpja.com/en-us/docs/glossary#recurso--resource) reports its own last update in an `updatedAt` field, in UTC, such as `company.taxRegime.updatedAt` and `stateRegistry.updatedAt`. 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](https://cnpja.com/en-us/docs/api/max-age).

### What does status 206 mean?

It is a [partial success](https://cnpja.com/en-us/docs/glossary#sucesso-parcial--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](https://cnpja.com/en-us/docs/api/limits-and-errors#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.taxRegime.maxAge` updates only the option for the Simples Nacional, for SIMEI and for the IBS and CBS regular regime; see [Tax regime in the API](https://cnpja.com/en-us/docs/api/tax-regime).

### Which codes identify an MEI and a Simples Nacional hybrid company?

In `company.taxRegime.type.code`, an MEI has `SIMPLES_NACIONAL_SIMEI`, a Simples Nacional hybrid company has `SIMPLES_NACIONAL_HYBRID`, and other Simples Nacional optants have `SIMPLES_NACIONAL`. Use `type.code`, not `simeiStartDate`, which can be `null` even for an MEI, and keep in mind that the regime may be [estimated](https://cnpja.com/en-us/docs/data/tax-regime#estimated). The matching search filters are in [Tax regime in the API](https://cnpja.com/en-us/docs/api/tax-regime).

### How do I request state registrations from other states?

On Lookup CNPJ, `stateRegistry.states` 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.view=DETAILED` each requested state is charged separately, as [All states: mind the cost](https://cnpja.com/en-us/docs/data/state-registrations#all-states-cost) warns. The parameters are in [State registrations in the API](https://cnpja.com/en-us/docs/api/state-registrations).

### 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_NOT_FOUND` 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](https://cnpja.com/en-us/docs/data/state-registrations#individuals).

### 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](https://cnpja.com/en-us/docs/data/partners-and-qsa#masked-cpf) explains; the parameters are in [Partners and people in the API](https://cnpja.com/en-us/docs/api/partners).

### How do I find a person's companies in the API?

Each partner is a [person](https://cnpja.com/en-us/docs/glossary#pessoa--person) with its own `id`, a stable UUID that is neither the CPF nor the CNPJ. With the `id`, read from `company.partners[].person.id` or from Search people, [Lookup person](https://cnpja.com/en-us/docs/api/reference#tag/people/GET/v2/people/%7bid%7d) returns the current participations in `participations`; see [Partners and people in the API](https://cnpja.com/en-us/docs/api/partners).

### Why are an address's coordinates null?

`address.coordinates` 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.coordinates` for that address repeats the calculation and is charged according to the [metering rules](https://cnpja.com/en-us/legal/metering#api-cnpj). Coordinate precision is covered in [Precision](https://cnpja.com/en-us/docs/data/location#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_CODE_NOT_FOUND`, charged when the request has a key; see [CEPs and addresses in the API](https://cnpja.com/en-us/docs/api/postal-codes).

### How do I leave deactivated CEPs out of Search CEP?

Send `status.code.in=ACTIVE`. A deactivated CEP has `status.code` 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](https://cnpja.com/en-us/docs/api/postal-codes) and, for the concept, [CEPs, streets and IBGE codes](https://cnpja.com/en-us/docs/data/postal-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](https://cnpja.com/en-us/docs/api/cnpj-search).

### How do I search only the CNPJs of a list?

On Search CNPJ, send the [list](https://cnpja.com/en-us/docs/glossary#lista--list) `id` in `lists.some` to search only its CNPJs, or in `lists.none` to leave them out. Lists are created with [Create list](https://cnpja.com/en-us/docs/api/reference#tag/lists/POST/v2/lists); see [CNPJ search and lists in the API](https://cnpja.com/en-us/docs/api/cnpj-search).

### 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](https://cnpja.com/en-us/docs/api/responses).

## Limits and errors

### What does status 429 mean?

The organization went over the requests-per-second limit (`RATE_LIMIT_EXCEEDED`) or the concurrent-request limit (`CONCURRENCY_LIMIT_EXCEEDED`), 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](https://cnpja.com/en-us/docs/api/limits-and-errors#limit-exceeded).

### What does status 402 mean?

The organization's quota or overage budget is used up, and the `code` tells which: `CACHED_QUERY_QUOTA_EXCEEDED`, `LIVE_QUERY_QUOTA_EXCEEDED` or `OVERAGE_BUDGET_EXCEEDED`, described in [Error codes](https://cnpja.com/en-us/docs/api/limits-and-errors#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](https://cnpja.com/en-us/docs/billing/quota-exhausted#ways-out).

### 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_TIMED_OUT`, and a client with a shorter timeout closes the connection first and loses the `traceId`; see [Timeout and size](https://cnpja.com/en-us/docs/api/limits-and-errors#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](https://cnpja.com/en-us/docs/api/limits-and-errors#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](https://cnpja.com/en-us/docs/api/limits-and-errors#trace-id).

## 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](https://cnpja.com/en-us/docs/billing/queries-and-quotas#shared). 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](https://cnpja.com/en-us/docs/api/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](https://cnpja.com/en-us/docs/api/migration/cnpja-v1).
