Migrate from ReceitaWS to CNPJAPI
Already integrating ReceitaWS? CNPJAPI replies in the same format, field by field. The migration is drop-in: swap the host of your call and your JSON-parsing code stays the same. This guide walks you through it.
What changes (and what doesn't)
- The host changes:
www.receitaws.com.brbecomesapi.cnpjapi.com.br. - Authentication changes: CNPJAPI requires your API key in the
Authorization: Bearerheader. Create your account at https://app.cnpjapi.com.br and generate the key (see Authentication). - The JSON body does not change: the same field names, in the same place (
nome,fantasia,situacao,atividade_principal,qsa, ...). Your parser stays the same.
Step by step
Before (ReceitaWS)
curl https://www.receitaws.com.br/v1/cnpj/00776574000156
After (CNPJAPI)
curl https://api.cnpjapi.com.br/v1/cnpj/00776574000156 \
-H "Authorization: Bearer cnpj_your_key"
The GET /v1/cnpj/{cnpj} path mirrors the ReceitaWS URL - migrating is swapping the host and adding the header. Alternatively, the canonical endpoint accepts GET /{cnpj}?formato=receitaws, with the same compatible response.
Code example
The Node examples use native
fetch(Node 18+) and top-levelawait- run them as an ES module (.mjs, or"type": "module"inpackage.json), or wrap the code in anasyncfunction.
Node.js (only the host and the header change versus your current code):
const cnpj = "00776574000156";
const response = await fetch(`https://api.cnpjapi.com.br/v1/cnpj/${cnpj}`, {
headers: { Authorization: "Bearer cnpj_your_key" },
});
const company = await response.json();
console.log(company.nome, company.situacao); // same fields as ReceitaWS
Python:
import requests
cnpj = "00776574000156"
r = requests.get(
f"https://api.cnpjapi.com.br/v1/cnpj/{cnpj}",
headers={"Authorization": "Bearer cnpj_your_key"},
)
company = r.json()
print(company["nome"], company["situacao"]) # same fields as ReceitaWS
Things to watch
The goal is property parity - the same field names, in the same place. A few details inherited from ReceitaWS:
statusis"OK"on success and"ERROR"on error ({"status":"ERROR","message":"..."}).atividades_secundariaswith no items carries the sentinel[{"code":"00.00-0-00","text":"Não informada"}], just like ReceitaWS.simplesandsimeiare always present (fields comefalse/nullwhen the company is not opted in).- ReceitaWS's proprietary
billingfield is omitted. - When you exceed the limit, the response is
429with theRetry-Afterheader (see Limits and plans).
The full table of differences is in ReceitaWS-compatible.
Batch lookup
The compatible mode also applies to batch - up to 20 CNPJs in a single call, in the same format. See Batch lookup.
Next steps
- ReceitaWS-compatible - the full contract of the format.
- Look up a CNPJ - CNPJAPI's native format (PascalCase), more complete.
- Authentication - generate your API key.
Create your free account at https://app.cnpjapi.com.br and migrate from ReceitaWS by swapping only the host.