Learn how to consult company data through the CNPJ using the CNPJ.ws API, with data from Receita Federal, Sintegra, and Suframa using Javascript/Node.js
Consulting a CNPJ using the CNPJ.ws API with Javascript and Node.JS is very easy!
Keeping customer/supplier records up to date or even querying company data to facilitate some internal registration of your system is very common, and the CNPJ.ws API provides an easy and quick way to develop this integration.
With the integration, we can use the API to query the address, state registration, registration status, CNAE, and many other information that may be important when registering a customer or supplier through the CNPJ.
The data returned by the API is obtained from various public agencies (Receita Federal, Sintegra, SERPRO, Suframa, etc.), aggregated and organized to facilitate use by other systems through a Rest API.
Installation
We have developed a package to facilitate this integration, see it on Github.
Remember that you can use our free API to consult CNPJ or you can purchase one of our commercial plans.
To get started, let's install the package:
Using YARN:
yarn add consultar-cnpj
Using NPM:
npm i consultar-cnpj --save
Usage
CNPJ.ws has a Public API and a Commercial API. To use the Public API, you do not need a token, but you can only make up to 3 queries per minute. If you are using the Commercial API, you must pass the token as the second parameter in the query to use its benefits. You can see more details about the commercial plans on our main page.
const consultarCNPJ = require("consultar-cnpj");
async function getCNPJ() {
const token = "INFORME O SEU TOKEN DE ACESSO";
try {
// O Token é opcional
const empresa = await consultarCNPJ("40154884000153", token);
console.log(empresa);
} catch (e) {
console.log(e);
}
}