Introduction to CNPJ
CNPJ (Cadastro Nacional da Pessoa Jurídica) is the national registry of legal entities in Brazil. It’s a unique identifier issued to companies and other types of legal entities that operate in the country. Understanding and utilizing CNPJ data can be incredibly useful for businesses, developers, and government agencies. In this article, we will explore dozens of useful APIs that interact with CNPJ data, including practical code snippets and an app example to get you started.
Top APIs for CNPJ
Here are some of the most popular and useful APIs that help you work with CNPJ data in Brazil:
ReceitaWS
This API allows you to get complete CNPJ data from Receita Federal.
fetch('https://www.receitaws.com.br/v1/cnpj/00000000000191')
.then(response => response.json())
.then(data => console.log(data));
BrasilAPI
BrasilAPI provides a comprehensive API for various Brazil-specific data, including CNPJ.
fetch('https://brasilapi.com.br/api/cnpj/v1/00000000000191')
.then(response => response.json())
.then(data => console.log(data));
Receita Federal
The Receita Federal’s API enables the verification of CNPJ registration.
fetch('https://receita.economia.gov.br/ws/cnpj/00000000000191')
.then(response => response.json())
.then(data => console.log(data));
CNPJ.IO
CNPJ.IO offers detailed information related to CNPJ and companies in Brazil.
fetch('https://cnpj.io/api/v1/cnpj/00000000000191')
.then(response => response.json())
.then(data => console.log(data));
Building an App with CNPJ APIs
Now, let’s create a simple Node.js application that utilizes these APIs.
const express = require('express');
const fetch = require('node-fetch');
const app = express();
app.get('/cnpj/:id', async (req, res) => {
const cnpjId = req.params.id;
const response = await fetch(`https://www.receitaws.com.br/v1/cnpj/${cnpjId}`);
const data = await response.json();
res.json(data);
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
With this app, you can access detailed CNPJ information by visiting http://localhost:3000/cnpj/00000000000191
.
Hash: 598eb236dc5a399de8fe06f3c00790852caaf55162a4253804bdaa849f79d2ca