Stenfrank / ubl21dian

Core for electronic invoicing pre-validation - DIAN UBL 2.1
https://soenac.com/ubl21-dian
17 stars 16 forks source link

AUXILIO - Menssage: "Unauthenicated" #6

Open carlillus opened 4 years ago

carlillus commented 4 years ago

Saludos.

¿Alguien me puede Ayudar?

Alguien a consumido el API REST desde Visual FoxPro?

### Ya hice la prueba desde el PostMan y hace la prueba perfectamente.

Tengo un ERP en Visual FoxPro:

Menssage: "Unauthenicated"

### EN TEORIA creo que mi problema esta en la Conexión desde VFP pero espero su ayuda.

Un compañero envió este código en VB6:

If RSRS.RecordCount > 0 Then
    ReenviarFacturaAPI:Set xmlhttp = New MSXML2.ServerXMLHTTP60

If TipoInvoice = "GENERAL" Then
    If RSCajaFE.Fields("TestSetIDFE") = "" Or IsNull(RSCajaFE.Fields("TestSetIDFE")) Then
        xmlhttp.Open "POST", RSRS.Fields("UrlAPI21") & "/api/ubl2.1/invoice", False
    Else
        xmlhttp.Open "POST", RSRS.Fields("UrlAPI21") & *"/api/ubl2.1/invoice/" & RSCajaFE.Fields("TestSetIDFE"), False
    End If
Else
    If TipoInvoice = "AIU" Then
        If RSCajaFE.Fields("TestSetIDFE") = "" Or IsNull(RSCajaFE.Fields("TestSetIDFE")) Then
            xmlhttp.Open "POST", RSRS.Fields("UrlAPI21") & "/api/ubl2.1/invoice-aiu", False
        Else
            xmlhttp.Open "POST", RSRS.Fields("UrlAPI21") & "/api/ubl2.1/invoice-aiu/" & RSCajaFE.Fields("TestSetIDFE"), False
        End If
    Else
        If TipoInvoice = "EXPORTACION" Then
            If RSCajaFE.Fields("TestSetIDFE") = "" Or IsNull(RSCajaFE.Fields("TestSetIDFE")) Then
                xmlhttp.Open "POST", RSRS.Fields("UrlAPI21") & "/api/ubl2.1/invoice-export", False
            Else
                xmlhttp.Open "POST", RSRS.Fields("UrlAPI21") & "/api/ubl2.1/invoice-export/" & RSCajaFE.Fields("TestSetIDFE"), False
            End If
        End If
    End If
End If

xmlhttp.setRequestHeader "accept", "application/json"
xmlhttp.setRequestHeader "Authorization", "Bearer " & Trim(RSRS.Fields("PasswordAPI"))
xmlhttp.setRequestHeader "Content-Type", "application/json"
xmlhttp.setRequestHeader "X-CSRF-TOKEN", " "
xmlhttp.send *PlantillaJSON

Yo uso este Código en VFP9:

ruta = "http://localhost/apidian2020/public/api/ubl2.1/invoice/e423daa7-201c-4bf9-a751-acebd3e3984a"    
token = "08f86bff3506b88fb95812d8942b4f138c84470bb72026abdfc4443b1038adea"
post_connect = CREATEOBJECT('MSXML2.ServerXMLHTTP') 
post_connect.Open("POST", ruta, .F.)
*******
post_connect.setRequestHeader("accept", "application/json") 
post_connect.setRequestHeader("Content-Type", "application/json")   
post_connect.setRequestHeader("Authorization", "Bearer Token="+token)
*******
post_connect.Send(json_para_envio)
json_respuesta = post_connect.responsetext

Pero en JSON_RESPUESTA me devuelve Menssage: "Unauthenicated"

DD4F commented 4 years ago

Saludos Verifica el TOKEN