They gave me an unpleasant mission to consult on the basis of the Federal Revenue Service the situation of several CNPJ's (more than 1000).
Is there any programmatic way to do this, preferably with no cost?
They gave me an unpleasant mission to consult on the basis of the Federal Revenue Service the situation of several CNPJ's (more than 1000).
Is there any programmatic way to do this, preferably with no cost?
One possibility for those who have a digital certificate (e-CNPJ, NFe etc.) is to use the system provided by SEFAZ as part of the NFe structure:
CadConsultaCadastro2
I will take as an example the webservice address of the State of São Paulo:
https://nfe.fazenda.sp.gov.br/ws/cadconsultacadastro2.asmx
As the SEFAZ documentation is a bit complex to understand, I will simplify and display the request in its entirety, as it becomes easier for everyone to adapt to their environment.
Here is the complete SOAP 1.2 request, which must be done with HTTPS using the digital certificate:
POST /ws/cadconsultacadastro2.asmx HTTP/1.1
Host: nfe.fazenda.sp.gov.br
Content-Type: application/soap+xml; charset=utf-8;
action="http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2/consultaCadastro2
Content-Length: 0000
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Header>
<nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2">
<cUF>35</cUF>
<versaoDados>2.00</versaoDados>
</nfeCabecMsg>
</soap12:Header>
<soap12:Body>
<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2">
<ConsCad xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.00">
<infCons>
<xServ>CONS-CAD</xServ>
<UF>SP</UF>
<CNPJ>00000000000000</CNPJ>
</infCons>
</ConsCad>
</nfeDadosMsg>
</soap12:Body>
</soap12:Envelope>
Line breaks and spaces between tags are just for easy reading. SEFAZ chose XML as the format to pack the data, but ... by saving space ... makes us work as if it were TXT. Then send everything queued in one line (except the POST headers and the blank line separating it from the BODY).
The Content-length:
must be computed by POST body size, it is the amount of bytes from <?xml
onwards.
The CNPJ must be filled in with 14 digits, with no dashes or dashes
The UF field is the acronym, but the cUF field is the numeric state code.
Each state has its own address, and the request must be made to the corresponding SeFaz.
It seems that Amazon does not make this service available.
Follow the webservices address of each region:
link
I imagine there is a limit of queries x time, but I did not find these measures in the entire SeFaz documentation. I suggest doing the consultation in small lots and at reasonable intervals. As mentioned by your colleague @Denis , you have some general recommendations on a PDF of SEFAZ .
Over time this answer will be outdated. Anyone who has problems to implement, leave a comment that as much as possible we can keep it updated.
Thanks to @jbueno and @Cigano, who helped develop and test before the response was published.