Consulting multiple Cnpjs situation in the IRS

Asked

Viewed 2,002 times

18

They gave me an ungrateful mission to consult in the base of the IRS the situation of several CNPJ’s (more than 1000).

Is there any programmatic way to do this, and preferably not cost?

  • +1, From what I know only accredited companies can have a web service to perform this, is they are paid, would be of great help a free API to perform these queries.

  • @Gabrielrodrigues There are companies that do batch too. In my view, the Department of Finance could make this base more accessible.

1 answer

15


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 address of webservice of the State of São Paulo:

https://nfe.fazenda.sp.gov.br/ws/cadconsultacadastro2.asmx

As the SEFAZ documentation is somewhat complex to understand, I will simplify and show the request in full, as it is easier for each one to adapt to their environment.

Follow the complete request in SOAP 1.2, which should 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>

Important:

  • Line breaks and spaces between tags are just for easy reading. SEFAZ chose XML as a format to package the data, but ...for space saving... makes us work as if it were TXT. Then send everything lined up in one line (except the POST headers and the blank line that separates it from BODY).

  • The Content-length: shall be calculated according to the body size of the POST, is the amount of bytes of <?xml onward.

  • The CNPJ must be completed with 14 digits, without dots or dashes

  • The UF field is the acronym, but the Cuf field is the state numeric code.

  • Each state has its own address, and the request must be made to the corresponding Sefaz.

  • It seems to me that the Amazon does not provide this service.

  • Follows the address of webservices of each region:
    http://www.nfe.fazenda.gov.br/portal/WebServices.aspx

  • I imagine there is a limit of queries x time, but I did not find these measures in the documentation all scattered from Sefaz. I suggest consulting in small batches and at reasonable intervals. As mentioned by the colleague @Denis, has some general recommendations in a PDF of the SEFAZ.

  • In time this answer will become outdated. Those who have problems to implement, leave a comment that as far as possible we can keep it updated.

Thanks to @jbueno and @Cigano, who helped develop and test prior to the publication of the answer.

  • 1

    @Bacchus, I found those time limit information

  • 1

    @Denisrudneideouza your avatar reminded me of that clip

  • 1

    @Denisrudneidesouza to advance part of the curiosity, is a clip of Goldfrapp, follows a frame of reference https://s-media-cache-ak0.pinimg.com/originals/fa/d0/e9/fad0e9444b2d63745a46a7352de76a4a.jpg

Browser other questions tagged

You are not signed in. Login or sign up in order to post.