Fechar
esqueci a minha senha
criar uma conta

Obter XML da Nota Fiscal API 2.0

Serviço destinado a obter os dados de uma Nota Fiscal.

ElementoTipoOcorrênciaDescrição
tokenstringobrigatórioChave gerada para identificar sua empresa
idintobrigatórioNúmero de identificação da nota fiscal no Tiny
ElementoTipoTamanhoOcorrênciaDescrição
retorno--obrigatórioElemento raiz do retorno
retorno.status_processamentoint-obrigatórioConforme tabela "Status de Processamento"
retorno.statusstring-obrigatórioContém o status do retorno “OK” ou “Erro”. Para o caso de conter erros estes serão descritos abaixo
retorno.codigo_erro (1)int-condicionalConforme tabela "Códigos de erro"
retorno.erros[ ] (1) (3)list-condicional [0..n]Contém a lista dos erros encontrados.
retorno.erros[ ].errostringstringcondicionalMensagem contendo a descrição do erro
retorno.xml_nfe (2)string1000condicionalXML da Nota fiscal enviado ao SEFAZ.

(1) - Somente estará presente no retorno caso o elemento "status" seja "Erro".
(2) - Somente estará presente no retorno caso o elemento "status" seja "OK".
(3) - Estes campos somente serão informados caso o retorno contenha erros.


$url = 'https://api.tiny.com.br/api2/nota.fiscal.obter.xml.php';
$token = 'coloque aqui a sua chave da api';
$id = 'xxxxx';
$data = "token=$token&id=$id";

enviarREST($url, $data);    

function enviarREST($url, $data, $optional_headers = null) {
	$params = array('http' => array(
		'method' => 'POST',
	    'content' => $data
	));
	
	if ($optional_headers !== null) {
		$params['http']['header'] = $optional_headers;
	}
	
	$ctx = stream_context_create($params);
	$fp = @fopen($url, 'rb', false, $ctx);
	if (!$fp) {
		throw new Exception("Problema com $url, $php_errormsg");
	}
	$response = @stream_get_contents($fp);
	if ($response === false) {
		throw new Exception("Problema obtendo retorno de $url, $php_errormsg");
	}
	
	return $response;
}

$client = new nusoap_client("https://api.tiny.com.br/api2.php?wsdl", true);
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;

$result = $client->call("obterXMLNotaFiscal", array('token' => 'xxxxx','id'=>'xxxxx'));

$res = array();
if ($client->fault) {
	$retorno = $result['faultstring'];		
} else {
	$err = $client->getError();
	if ($err) {
		$retorno = $err;	    	
	} else {
		$retorno = $result;
	}
}
<?xml version="1.0" encoding="UTF-8"?>
<retorno>
  <status_processamento>1</status_processamento>
  <status>Erro</status>
  <codigo_erro>2</codigo_erro>
  <erros>
    <erro>token invalido</erro>
  </erros>
</retorno>
<?xml version="1.0" encoding="UTF-8"?>
<retorno>
  <status_processamento>2</status_processamento>
  <status>Erro</status>
  <codigo_erro>32</codigo_erro>
  <erros>
    <erro>Nota Fiscal não localizada</erro>
  </erros>
</retorno>
<?xml version="1.0" encoding="UTF-8"?>
<retorno>
  <status_processamento>3</status_processamento>
  <status>OK</status>
  <xml_nfe>
    <nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.00">
      <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
        <infNFe versao="2.00" Id="NFe43121191184036000128550010006000601509770892">
          <ide>
            <cUF>43</cUF>
            <cNF>50977089</cNF>
            <natOp>Venda e-commerce</natOp>
            <indPag>2</indPag>
            <mod>55</mod>
            <serie>1</serie>
            <nNF>600060</nNF>
            <dEmi>2012-11-14</dEmi>
            <tpNF>1</tpNF>
            <cMunFG>4302105</cMunFG>
            <tpImp>1</tpImp>
            <tpEmis>1</tpEmis>
            <cDV>2</cDV>
            <tpAmb>2</tpAmb>
            <finNFe>1</finNFe>
            <procEmi>0</procEmi>
            <verProc>TinyOffice 1.0</verProc>
          </ide>
          <emit>
            <CNPJ>91184036000128</CNPJ>
            <xNome>Empresa Teste LTDA</xNome>
            <xFant>Empresa Teste</xFant>
            <enderEmit>
              <xLgr>Rua Visconde de Sao Gabriel</xLgr>
              <nro>100</nro>
              <xCpl>Sala 59</xCpl>
              <xBairro>Cidade Alta</xBairro>
              <cMun>4302105</cMun>
              <xMun>Bento Goncalves</xMun>
              <UF>RS</UF>
              <CEP>95700000</CEP>
              <cPais>1058</cPais>
              <xPais>Brasil</xPais>
            </enderEmit>
            <IE>0100035485</IE>
            <CRT>3</CRT>
          </emit>
          <dest>
            <CNPJ>99999999000191</CNPJ>
            <xNome>NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL</xNome>
            <enderDest>
              <xLgr>zds</xLgr>
              <nro>056</nro>
              <xBairro>masasd</xBairro>
              <cMun>4302105</cMun>
              <xMun>Bento Goncalves</xMun>
              <UF>RS</UF>
              <CEP>95700000</CEP>
              <cPais>1058</cPais>
              <xPais>Brasil</xPais>
            </enderDest>
            <IE/>
          </dest>
          <det nItem="1">
            <prod>
              <cProd>561</cProd>
              <cEAN/>
              <xProd>Abacaxi Crocante Liofilizado - 40g - Masterfrut</xProd>
              <NCM>10011010</NCM>
              <CFOP>5102</CFOP>
              <uCom>UN</uCom>
              <qCom>1.0000</qCom>
              <vUnCom>10.0000000</vUnCom>
              <vProd>10.00</vProd>
              <cEANTrib/>
              <uTrib>UN</uTrib>
              <qTrib>1.0000</qTrib>
              <vUnTrib>10.0000000</vUnTrib>
              <indTot>1</indTot>
            </prod>
            <imposto>
              <ICMS>
                <ICMS00>
                  <orig>0</orig>
                  <CST>00</CST>
                  <modBC>3</modBC>
                  <vBC>10.00</vBC>
                  <pICMS>17.00</pICMS>
                  <vICMS>1.70</vICMS>
                </ICMS00>
              </ICMS>
              <IPI>
                <cEnq>999</cEnq>
                <IPINT>
                  <CST>52</CST>
                </IPINT>
              </IPI>
              <PIS>
                <PISOutr>
                  <CST>49</CST>
                  <vBC>10.00</vBC>
                  <pPIS>0.00</pPIS>
                  <vPIS>0.00</vPIS>
                </PISOutr>
              </PIS>
              <COFINS>
                <COFINSOutr>
                  <CST>49</CST>
                  <vBC>10.00</vBC>
                  <pCOFINS>0.00</pCOFINS>
                  <vCOFINS>0.00</vCOFINS>
                </COFINSOutr>
              </COFINS>
            </imposto>
          </det>
          <total>
            <ICMSTot>
              <vBC>10.00</vBC>
              <vICMS>1.70</vICMS>
              <vBCST>0.00</vBCST>
              <vST>0.00</vST>
              <vProd>10.00</vProd>
              <vFrete>0.00</vFrete>
              <vSeg>0.00</vSeg>
              <vDesc>0.00</vDesc>
              <vII>0.00</vII>
              <vIPI>0.00</vIPI>
              <vPIS>0.00</vPIS>
              <vCOFINS>0.00</vCOFINS>
              <vOutro>0.00</vOutro>
              <vNF>10.00</vNF>
            </ICMSTot>
          </total>
          <transp>
            <modFrete>0</modFrete>
          </transp>
          <infAdic/>
        </infNFe>
        <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
          <SignedInfo>
            <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
            <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
            <Reference URI="#NFe43121191184036000128550010006000601509770892">
              <Transforms>
                <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
                <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
              </Transforms>
              <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
              <DigestValue>nv258e8HTTdh1AfMZ4+DUCAMyyk=</DigestValue>
            </Reference>
          </SignedInfo>
          <SignatureValue>GUd29UCXtiF5OLgUMC+U0RTWAeF/KOEOo5+hKJoyccpipckbG/PMpCYyFxR14aB70dBkKuzaFtMqSlkPUsG8ZS6PE3H+/hq2mF8JAgj6w21fvi2Ql6ViTKkMz0mgwsJ+SQjuEBBuipiW1feHT5gsSJFhotFBnR3I/XBJW2FaNyFkuGIYP6VVjsnDpqYdS2iJxZfIxFAqF/g3KTUjCC+i6UhsvWfmH3CT4pNtOpdw2Ncl8qPvXNA8gkND34JAdrBsoEs5GdqFgMpXde/HISyVLl+EYYJWP9RbOILxbnImxxeAjU+cSlFrB1w+k8YpGy2Ee1nqtxvvEQ8Rtfh/giFhEg==</SignatureValue>
          <KeyInfo>
            <X509Data>
              <X509Certificate>MIIIAjCCBeqgAwIBAgIIeJqr7PV4LSwwDQYJKoZIhvcNAQELBQAwdTELMAkGA1UEBhMCQlIxEzARBgNVBAoTCklDUC1Ccm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kkASRcL/XXvo5ilrnVt9PoFiKUfqEIKpau7M3pFNQehkCLB16AtKnwwdfYzhdzk7hCDXel77zCKf9sfcudeXEX+7gSknmK+LhK7hc0eR43GECKhuJsBBor/E8LnrlYk+4yWgYmtE4TXGmvO7wHpJiQqdT9qNoo7XbCkuyR7qSKz1+1ulK1uOg7jpHhFlxclofsy4xSJs2ludbiLHEH6qkKo7RknP3sbGDhrf+7fMSCjKwY6TUCRZgT181Fe6vCzWQ2ywd8jd0pOH2W30HWdYTv24l5ktvCMAAoQWvx9zsqdLtv5vDH9dyQoZR+UkFrzpaBmX4aZZ2hqMMcf5lEymwV3GvMt5N5CfaI9zE5lz57nVKW5Ea4pycA8uauoCvds78gt+/fBc0SamR7EYcsVrOagPawltp5blIsTH10ca/sg0ZhAlSq+XebpmbeXuPP8QXzSoG7f7e0WKn5/JYlTzF1F8RqmqYNOtD1cXABDDtjGQMDWBgjcrh344K5nelaoHhDU63qJ4=</X509Certificate>
            </X509Data>
          </KeyInfo>
        </Signature>
      </NFe>
      <protNFe versao="2.00">
        <infProt Id="ID143120002660037">
          <tpAmb>2</tpAmb>
          <verAplic>RS20121114111302</verAplic>
          <chNFe>43121191184036000128550010006000601509770892</chNFe>
          <dhRecbto>2012-11-14T14:13:36</dhRecbto>
          <nProt>143120002660037</nProt>
          <digVal>nv258e8HTTdh1AfMZ4+DUCAMyyk=</digVal>
          <cStat>100</cStat>
          <xMotivo>Autorizado o uso da NF-e</xMotivo>
        </infProt>
      </protNFe>
    </nfeProc>
  </xml_nfe>
</retorno>