# CNPJ card and PDF certificates in the API

> Issue the CNPJ card, the QSA and the Simples Nacional, CCC and SUFRAMA certificates as a single PDF via the API, with codes, max age and errors.

> **Tip:** Concepts on this page: [CNPJ card and other certificates](https://cnpja.com/en-us/docs/data/certificates), [Omitted certificates](https://cnpja.com/en-us/docs/data/certificates#omitted) and [Data freshness](https://cnpja.com/en-us/docs/data/freshness).

The API issues the [certificates](https://cnpja.com/en-us/docs/glossary#comprovante--certificate) of a CNPJ, in [Issue CNPJ dossier](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d/dossier), or of a CPF, in [Issue CPF dossier](https://cnpja.com/en-us/docs/api/reference#tag/individuals/GET/v2/individuals/%7btaxId%7d/dossier), and bundles them into a single PDF file, the [dossier](https://cnpja.com/en-us/docs/glossary#dossiê--dossier). Each certificate carries the registration at the source on the date of the query: the original PDF is worth what the source gives it, the reproduction generated by CNPJá carries no public faith, and neither replaces checking the source when the law requires it, as explained in [What a certificate is](https://cnpja.com/en-us/docs/data/certificates#what-it-is). Both operations always require an [API key](https://cnpja.com/en-us/docs/api/first-request).

## Request

| Operation | Method and path | Accepted certificates |
|---|---|---|
| [Issue CNPJ dossier](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d/dossier) | `GET /v2/establishments/{taxId}/dossier` | All five |
| [Issue CPF dossier](https://cnpja.com/en-us/docs/api/reference#tag/individuals/GET/v2/individuals/%7btaxId%7d/dossier) | `GET /v2/individuals/{taxId}/dossier` | `CCC_REGISTRATIONS` and `SUFRAMA_REGISTRATION` |

Each certificate has a code, sent in the `certificates` parameter. The content and source of each one are in [Available certificates](https://cnpja.com/en-us/docs/data/certificates#catalog).

| Code | Certificate |
|---|---|
| `RFB_REGISTRATION` | CNPJ registration and status, the cartão CNPJ |
| `RFB_PARTNERS` | Partners and administrators board |
| `SIMPLES_NACIONAL_OPTION` | Simples Nacional option |
| `CCC_REGISTRATIONS` | State registrations, in one state |
| `SUFRAMA_REGISTRATION` | SUFRAMA registration |

Both operations take the same parameters:

| Parameter | Location | Required | Content |
|---|---|---|---|
| `taxId` | Path | Yes | CNPJ with 14 characters or CPF with 11 digits, with no punctuation |
| `certificates` | Query | Yes | Certificate codes, separated by commas, with at least one and no repeats. The order of the codes sets the order in the PDF |
| `maxAge` | Query | No | Maximum data age accepted for cached certificates, from `5m` to `1y`. Default: `45d` |

- A code the operation does not accept, such as `RFB_REGISTRATION` in the CPF dossier, a repeated code or a `maxAge` in the wrong format are rejected with `400` `REQUEST_VALIDATION_FAILED`.
- Dossiers do not accept the access without a key described in [Public access](https://cnpja.com/en-us/docs/api/public-access): a request without a key returns `401` `API_KEY_MISSING`.

```http
GET /v2/establishments/37335118000180/dossier?certificates=RFB_REGISTRATION,RFB_PARTNERS HTTP/1.1
Host: api.cnpja.com
Authorization: YOUR_API_KEY
```

### Max age

Each requested certificate is compared with `maxAge` independently. Within the limit, it comes from cached data; if it is older, or was never issued, it is issued live at the source during the request. Outdated certificates are issued in parallel, so the response time follows the slowest issue.

- `maxAge` applies to every certificate in the request. There are no per-certificate limits, like `stateRegistry.maxAge` in Lookup CNPJ. The syntax is in [Max age and partial success](https://cnpja.com/en-us/docs/api/max-age#syntax).
- To require one recent certificate without forcing the issue of the others, request it in a separate request.

For a recent certificate, such as when approving a new customer, send a smaller `maxAge`:

```http
GET /v2/establishments/37335118000180/dossier?certificates=RFB_REGISTRATION&maxAge=1d HTTP/1.1
Host: api.cnpja.com
Authorization: YOUR_API_KEY
```

## Response

A `200` or `206` response is the PDF file itself, with `Content-Type: application/pdf`:

- **Order:** certificates appear in the order of the codes in `certificates`, each with all of its pages.
- **Omissions:** an unavailable certificate is left out of the file, with no notice page, as described in [Omitted certificates](#omitted).
- **Date:** certificates have no `updatedAt`, and the response does not state the date of each one. When the source prints the issue date, it is in the document itself.
- **Errors:** an error response comes as JSON, in the format described in [Limits and errors](https://cnpja.com/en-us/docs/api/limits-and-errors).
- **Compression:** the PDF is never compressed, even with `Accept-Encoding`.
- **Individual files:** the API does not split the dossier into separate files. To keep each certificate in its own PDF, send one request per certificate, with a single code in `certificates`. Each certificate is still charged separately, as in a dossier with several.

To save the dossier with curl and see the status at the end:

```bash
curl "https://api.cnpja.com/v2/establishments/37335118000180/dossier?certificates=RFB_REGISTRATION,RFB_PARTNERS" \
  -H "Authorization: YOUR_API_KEY" \
  -o dossier.pdf -w "%{http_code}\n"
```

With `200` or `206`, the file is the PDF. With any other status, it holds the error JSON. Check the status before filing the file as a certificate.

## CNPJ and CPF

### Issue CNPJ dossier

- The CNPJ has 14 characters, with no punctuation, uppercase letters in an [alphanumeric CNPJ](https://cnpja.com/en-us/docs/glossary#cnpj-alfanumérico--alphanumeric-cnpj) and valid check digits. Other formats are rejected with `400` `REQUEST_VALIDATION_FAILED`.
- A CNPJ that is not in cached data yet is queried live at the Receita Federal before the dossier is issued.
- `404` `ESTABLISHMENT_NOT_FOUND` means the CNPJ is not registered with the Receita Federal.

### Issue CPF dossier

Issue CPF dossier serves an [individual](https://cnpja.com/en-us/docs/glossary#indivíduo--individual), a natural person with a state registration in the CCC or a SUFRAMA registration, and does not issue certificates of the CPF registry at the Receita Federal, as explained in [CNPJ or CPF](https://cnpja.com/en-us/docs/data/certificates#cnpj-or-cpf).

```http
GET /v2/individuals/CPF_NUMBER/dossier?certificates=CCC_REGISTRATIONS,SUFRAMA_REGISTRATION HTTP/1.1
Host: api.cnpja.com
Authorization: YOUR_API_KEY
```

- The CPF has 11 digits, with no punctuation. The [masked CPF](https://cnpja.com/en-us/docs/glossary#cpf-mascarado--masked-cpf) of partners, such as `***456789**`, does not work with this operation. See [Partners and people in the API](https://cnpja.com/en-us/docs/api/partners).
- `CCC_REGISTRATIONS` is only issued when the CPF has a known state registration. Without one, this operation does not query the CCC: fetch the registrations first in [Lookup CPF](https://cnpja.com/en-us/docs/api/reference#tag/individuals/GET/v2/individuals/%7btaxId%7d), with `expand=stateRegistry` and the states in `stateRegistry.states`, as described in [State registrations in the API](https://cnpja.com/en-us/docs/api/state-registrations), then issue the dossier.
- `SUFRAMA_REGISTRATION` queries the SUFRAMA registry even for a CPF not yet known to the API.

> **Important:** `404` `INDIVIDUAL_NOT_FOUND` means the API knows no state registration of the CPF and SUFRAMA found no registration, when `SUFRAMA_REGISTRATION` is requested. A CPF not yet known to the API, requested only with `CCC_REGISTRATIONS`, returns `404` without querying any source. On the first request for a CPF there is no cached data to fall back on, and a SUFRAMA failure also results in `404`: when a `404` is unexpected, retry the request later.

## Omitted certificates

The dossier holds only the certificates that are available. The cases in which a certificate is left out, and what each one consumes, are in [Omitted certificates](https://cnpja.com/en-us/docs/data/certificates#omitted). In the response:

- The PDF has no notice page in place of an omitted certificate, and the response does not say which ones were left out.
- When none of the requested certificates is available, there is no PDF: the response is `404` `ESTABLISHMENT_DOSSIER_EMPTY` in Issue CNPJ dossier or `404` `INDIVIDUAL_DOSSIER_EMPTY` in Issue CPF dossier. That `404` consumes what each omitted certificate consumes, as in [Omitted certificates](https://cnpja.com/en-us/docs/data/certificates#omitted).
- When your integration already looks up the CNPJ as JSON with `company.taxRegime`, `stateRegistry` or `suframa` in `expand`, use the result to request only the certificates that should exist.
- To tell each omission apart, request one certificate per request, as described in [Response](#response).

## Partial success

Each live query has up to 30 seconds. If issuing a certificate fails or takes longer, the request goes on and the response comes with `206`, a [partial success](https://cnpja.com/en-us/docs/glossary#sucesso-parcial--partial-success):

- The body is a PDF, just like in a `200` response.
- The affected certificate comes in its cached version, which can be older than the requested `maxAge`, or is left out when none exists. If no certificate is left, the response is the `404` described in [Omitted certificates](#omitted).
- The affected certificate is not charged, even when its cached version is included, under the [metering rules](https://cnpja.com/en-us/legal/metering#not-charged). The others are charged normally.
- The response does not say which certificate failed.

Partial success needs cached data to fall back on. If the live query of a CNPJ that is not in cache yet fails, the request fails instead of returning `206`. In that case, retry later, as explained in [A CNPJ's first lookup](https://cnpja.com/en-us/docs/data/freshness#first-lookup).

> **Important:** treat `206` as success, but do not file the document as an up-to-date record when the decision requires a recent certificate. Retry the request later to get the updated version.

## Billing

Each requested certificate is charged separately, as live when it is issued during the request and as cached when it comes from cache, including the two Receita Federal certificates, which come from a single query at the source. The consumption of each case, including `404` responses, is in the metering rules, under [Issue certificates](https://cnpja.com/en-us/legal/metering#api-certificates).

> **Important:** a certificate left out because the source has no record is still charged, as the [metering rules](https://cnpja.com/en-us/legal/metering#charged-without-result) set, even when no certificate is left and the response is a `404`. Request only the certificates that should exist.

## Frequent errors

| Status | Code | Cause | Action |
|---|---|---|---|
| `400` | `REQUEST_VALIDATION_FAILED` | `certificates` missing, empty, with a repeated code or a code the operation does not accept; `maxAge` in the wrong format; malformed CNPJ or CPF; unknown parameter | Fix what `errors` points to |
| `401` | `API_KEY_MISSING` | Request without an API key. Dossiers do not accept public access | Send the key in the `Authorization` header |
| `402` | `CACHED_QUERY_QUOTA_EXCEEDED`, `LIVE_QUERY_QUOTA_EXCEEDED` or `OVERAGE_BUDGET_EXCEEDED` | The organization's quota or overage budget is used up. What each code means is in [Error codes](https://cnpja.com/en-us/docs/api/limits-and-errors#error-codes) | Follow one of the ways out in [Quota used up](https://cnpja.com/en-us/docs/billing/quota-exhausted#ways-out) |
| `404` | `ESTABLISHMENT_NOT_FOUND` | The CNPJ is not registered with the Receita Federal | Check the CNPJ. The `404` is also charged, under the [metering rules](https://cnpja.com/en-us/legal/metering#charged-without-result): retry only when the registration may have changed |
| `404` | `INDIVIDUAL_NOT_FOUND` | The API knows no state registration of the CPF and SUFRAMA found no registration, or failed on the first request for the CPF | Look up the registrations in Lookup CPF first or retry later, as described in [Issue CPF dossier](#issue-cpf-dossier) |
| `404` | `ESTABLISHMENT_DOSSIER_EMPTY` or `INDIVIDUAL_DOSSIER_EMPTY` | None of the requested certificates is available for the CNPJ or CPF, for the reasons in [Omitted certificates](https://cnpja.com/en-us/docs/data/certificates#omitted) | Request only the certificates that should exist. The `404` consumes what each omitted certificate consumes |
| `504` | `REQUEST_TIMED_OUT` | The request did not finish within 60 seconds | Retry with increasing intervals. The response is not charged |

Other errors are in [Limits and errors](https://cnpja.com/en-us/docs/api/limits-and-errors).

## Use cases

- **Customer onboarding:** when approving a customer, issue `RFB_REGISTRATION` and `RFB_PARTNERS` with a short `maxAge` and file the PDF with the customer record, as a record of the registration status and the partners on the date of the query.
- **Supplier qualification:** bundle the cartão CNPJ, QSA, Simples Nacional and CCC certificates into a single dossier and renew it periodically with the default `maxAge`.
- **Tax documentation:** as support for checking a tax rule, file the certificate you queried, such as `SIMPLES_NACIONAL_OPTION` when applying the treatment for opted-in companies, or `CCC_REGISTRATIONS` when checking the state registration of an NF-e recipient.
- **Sales to the Manaus Free Trade Zone:** file `SUFRAMA_REGISTRATION` with the invoice of incentivized sales, as described in [SUFRAMA in the API](https://cnpja.com/en-us/docs/api/suframa).
- **Rural producers:** issue `CCC_REGISTRATIONS` in the CPF dossier to document the state registration of producers who are natural persons.
- **Audit:** keep the dossier of the counterparties of relevant contracts and transactions with the documentation of each transaction.

## In the app

On the platform, the **Certificates** button on the record page issues the same certificates for a CNPJ, as a single PDF or one file per certificate, with the maximum age chosen in the dialog, as explained in [Issue certificates as PDF](https://cnpja.com/en-us/docs/companies/certificates). Certificates for a CPF exist in the API only.

## Notes

- A live issue can take a few seconds. Set your HTTP client timeout above 60 seconds, as [Limits and errors](https://cnpja.com/en-us/docs/api/limits-and-errors) explains.
- Keep the PDF you receive: every request is charged, even when the certificates come from cache.
- Keep the default `maxAge` for archiving and periodic reviews, shorten it only when the decision requires a recent certificate, and request both Receita Federal certificates together only when you need both.
- Responses carry no cost headers. The consumption of each request appears in [Requests](https://cnpja.com/en-us/organizations/current/usage-events).
- All parameters are in [Issue CNPJ dossier](https://cnpja.com/en-us/docs/api/reference#tag/establishments/GET/v2/establishments/%7btaxId%7d/dossier) and [Issue CPF dossier](https://cnpja.com/en-us/docs/api/reference#tag/individuals/GET/v2/individuals/%7btaxId%7d/dossier).
