# Refresh CNPJ data live

> How to refresh a CNPJ's data live from the Receita Federal, Simples Nacional, CCC and SUFRAMA, read the age of each source and adjust automatic updates.

Refreshing live queries the official source now and replaces, on screen, the stored data with the data of the moment. The controls sit at the top of the record page (**CNPJ** > legal name > **Update all**), in the **Sources** menu and next to the age of each section, and they work for members of an organization.

## Live and cached

Each part of the record comes from a source and is stored by CNPJá with the date of its last query. Opening the record shows that stored data, a [cached query](https://cnpja.com/en-us/docs/glossary#consulta-em-cache--cached-query). A [live query](https://cnpja.com/en-us/docs/glossary#consulta-em-tempo-real--live-query) asks the source again, takes a few seconds and updates what is stored. How the two work together is in [Data freshness: live and cached](https://cnpja.com/en-us/docs/data/freshness).

You can refresh five sources on the record:

| Source | What it refreshes |
| --- | --- |
| **Receita Federal** | **Overview**, **Contacts**, **Activities** and **Partners and administrators** |
| **Simples Nacional** | **Tax regime** |
| **CCC** | **State registrations** |
| **SUFRAMA** | **SUFRAMA** |
| **Geolocation** | The coordinates and the **Precision**, under **Geolocation** |

The coordinates are recomputed from the registered address, as explained in [Data sources](https://cnpja.com/en-us/docs/data/sources#google-maps). The street view and the aerial map are part of no refresh: they are only rendered when you click **Load**, as explained in [Map, street view and coordinates](https://cnpja.com/en-us/docs/companies/location).

Without an account or an organization, the refresh buttons carry a padlock with the hint **Requires an account**, and **Sources** shows **Live queries need an account.** See [Guests, accounts and organizations](https://cnpja.com/en-us/docs/app/access-levels#matrix).

## Age of each source

The age of each source shows in the header or footer of the section it feeds and under **Sources**, always beside a dot in the color of the reading's kind, as across the app: teal for live and grey for cache. The color tells the kind, never the age: an outdated reading keeps its grey dot, and it is the age that turns amber. The **Sections** band shows only the dot:

| State | Age | How it shows |
| --- | --- | --- |
| Live | Up to 1 hour | Teal dot. The details read **Live** |
| Fresh | Up to 7 days | Grey dot. The details read **Cache** |
| Outdated | Over 7 days | Grey dot and amber age. The details read **Cache** and **Outdated** |
| Never queried | No query | Hollow dot and **Never queried** |

**Geolocation** has no age, because the coordinates do not keep the date they were computed. It shows only **Updated**, when the record has coordinates, or **Never queried**, when it has none, whether they were never computed or the address was not located. The details read **Live** right after a computation made on the page and **Cache** otherwise.

The age is told relatively, such as "3 days ago". Hover over it (or tap) to see the exact date and time of the query, in your time zone ([Time zone and dates](https://cnpja.com/en-us/docs/app/preferences#time-zone)). Data that arrived with the source's open data publication, such as the Receita Federal's, shows only the publication date, with no time.

## Refresh everything

**Update all** queries every available source of the record live, at once. **Geolocation** joins only while it shows **Never queried**: coordinates the record already has are recomputed only from that source's own button, in **Sources** or in the section.

1. At the top of the record page, check the number next to **Update all**: it is the total of live queries the action uses. For the CCC, its share is an estimate from the registrations already known in the establishment's state, and usage follows the registrations the query finds, as in the [Metering Rules](https://cnpja.com/en-us/legal/metering#platform). On smaller screens the button shows only its icon, and the cost shows when you hover.
2. Click **Update all**.
3. In the **Run live queries?** confirmation, check the receipt, with one line per source and the **Total**.
4. Click **Query**, or **Cancel** to give up.

Each source is queried separately, so a slow source does not hold back the others. Each section updates as soon as its source answers, and a beam of light runs along the section while it waits. Once the answers are in, the **Record updated in real time** notice appears.

If you leave the record before the answers arrive, the page stops waiting for them and does not show what comes back later.

## Refresh one source

To refresh a single source:

1. Click the arrow next to **Update all** to open **Sources**.
2. Check the age of each source and its automatic rule, such as "Auto 7d". **Geolocation** shows **Updated** or **Never queried** instead of an age.
3. Click the refresh button next to the source. The hint says what it does, such as "Run a live query: Receita Federal", and its cost: **Consumes one live query**. For the CCC, the cost counts one query per registration already known in the establishment's state, at least one, such as "Consumes 3 live queries", and goes through the confirmation when it is more than one.

The same button shows in the header or footer of each section, next to the age or, under **Geolocation**, the state. An action that costs a single query runs without confirmation. When it costs more, the **Run live queries?** confirmation comes first, as with **Update all**.

## State registrations by state

The CCC answers per state. In the **State registrations** panel, each state has a band with the age of its query, such as "CCC - SP", and a refresh button of its own. A registration marked **No details · query the state** does not yet have the data only the state's query brings.

1. Under **State registrations**, find the state's band.
2. Click the band's refresh button. If more than one state is waiting for details, use **Fetch missing details**, at the top of the panel, to query them all.
3. If the confirmation appears, check the receipt and click **Query**.

The receipt recalls the CCC rule: **CCC: 1 query per registration · at least 1 per state**. Establishments abroad have no state, and the CCC is locked with the hint **Establishments abroad have no state to query**. What the details add is covered in [State registration and CCC](https://cnpja.com/en-us/docs/data/state-registrations#detail-levels).

## Automatic updates

> **Important:** automatic updates are on by default. When a record opens, each source older than this browser's rule, or never queried, is queried live automatically. Opening a record can use the organization's live queries, without confirmation. Usage follows the [Metering Rules](https://cnpja.com/en-us/legal/metering#auto-refresh) and the [Terms of Use](https://cnpja.com/en-us/legal/terms#quotas).

The default rule is **Older than 7 days** for the Receita Federal, the Simples Nacional, the CCC and SUFRAMA, and **When never queried** for **Geolocation**: every source marked **Outdated** or **Never queried** is queried on open. The update runs once per opening, for members only, and, for the CCC, includes the details of the registrations in the establishment's state, never those of other states. After it, reopening the record within the rule's window does not query again.

Automatic updates only run the queries that fit in what is left of the live query quota and of the overage budget. With the quota used up and no overage to pay for it, no source is queried on open and no notice appears: the record opens with the stored data, like any cached lookup. The quota used up notice only appears when you click **Update all** or a source's button, as explained in [Quota used up](https://cnpja.com/en-us/docs/billing/quota-exhausted).

> **Important:** under the default rule, a record without coordinates queries **Geolocation** live as it opens. An address that cannot be located stays without coordinates and marked **Never queried**, so it is queried and charged again on every opening, until you choose **Never** for **Geolocation**. See [Address not located](https://cnpja.com/en-us/docs/data/location#address-not-located) and the usage in the [Metering Rules](https://cnpja.com/en-us/legal/metering#auto-refresh).

To change the rule:

1. At the top of the record page, click the arrow next to **Update all** to open **Sources**.
2. At the foot of the menu, click **Automatic updates**.
3. For each source, pick a rule on the ruler of options.
4. Click **Close**. The choice applies right away.

| Option on the ruler | Rule | When the source is queried on open |
| --- | --- | --- |
| **Never** | **Never** | Never. The source is only queried when you click |
| **If never** | **When never queried** (default for **Geolocation**) | Only if the source was never queried for the CNPJ. For **Geolocation**, whenever the record has no coordinates |
| **1 hour** | **Older than 1 hour** | When the last query is over 1 hour old, or there was none |
| **1 day** | **Older than 1 day** | When it is over 1 day old, or there was none |
| **7 days** | **Older than 7 days** (default for the other sources) | When it is over 7 days old, or there was none |
| **30 days** | **Older than 30 days** | When it is over 30 days old, or there was none |

**Geolocation** has only **Never** and **If never**: since the coordinates carry no date, there is no age to choose. On each source's ruler, a dot marks the default rule, as the **Default** legend in the dialog's footer recalls.

Next to each source, the dialog shows what the rule would do with the open record: **Would query on open**, **Up to date**, **Not queried on open** or **Unavailable**. Under **Sources**, each source shows the rule in force, such as "Auto 7d" or, for **Geolocation**, "Auto If never".

The choice is saved in this browser, as the dialog's footer notes (**Saved in this browser**), and does not follow your account: another browser or device uses the default rule until it is set. What else stays in the browser is covered in [Data stored in your browser](https://cnpja.com/en-us/docs/privacy/browser-data).

> **Tip:** to use live queries only when you click, choose **Never** for every source. The record still opens with the stored data and the age of each item.

## Quota usage

Every refresh, manual or automatic, uses live queries of the selected organization; guests and accounts without an organization use none. The usage of each action is in the [Metering Rules](https://cnpja.com/en-us/legal/metering#platform), and that of automatic updates under [Automatic updates](https://cnpja.com/en-us/legal/metering#auto-refresh).

## Common problems

When a query fails, a notice names the source and the section keeps its previous data:

| Message | What to do |
| --- | --- |
| **The source took too long to answer, try again in a moment** | The official source is slow or down. Try again later |
| **Your session expired, sign in again to run live queries** | Sign in again and repeat the refresh |
| **The Receita Federal no longer lists this CNPJ** | The Receita Federal no longer finds the CNPJ. The page keeps the last data obtained. See [Registration status](https://cnpja.com/en-us/docs/data/registration-status#statuses) |
| **The live query failed, try again in a moment** | A momentary failure. Try again in a moment |
| **The source answered only in part, try again in a moment** | The source brought only part of what was asked: what it answered is already on screen, and the rest stays as it was. Try again in a moment |
| **Live query allowance used up** or **This month's overage budget doesn't cover this** | The organization used up its quota, or what is left of its overage budget doesn't cover the query. See the ways out in [Quota used up](https://cnpja.com/en-us/docs/billing/quota-exhausted) |

Other cases:

- **Padlock on the button:** the hint **Requires an account** means you need to sign in and belong to an organization.
- **Spinning button:** the query for that source is still running. Wait for the answer.
- **Nothing was queried on open:** check **Automatic updates**. The rule may be set to **Never**, the source may be **Up to date**, the rule may have been chosen in another browser, or the live query quota may be used up, with no overage to pay for it.

More cases in [Troubleshooting](https://cnpja.com/en-us/docs/support/troubleshooting).

## In the API

In the API, each request sets the age it accepts with the `maxAge` parameter: a resource older than that is queried live. See [Max age and partial success](https://cnpja.com/en-us/docs/api/max-age).
