Get dafrom API REST (method GET)

69 views
Skip to first unread message

Sebastián BASSANO

unread,
Dec 24, 2021, 10:02:24 AM12/24/21
to
Hi, i'm trying to consume API REST from VO.
For example:

https://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD

returns

["Error de autenticaci\u00f3n (2) USER"]

but from VO i always get empty response.
I try:

Option 1
cRequest:= "authUser=USER&authPass=PASSWORD"
oHttpSession:= CHttp{"SENASA.APIREST"}
IF oHttpSession:ConnectRemote("http://test.senasa.gov.ar")
IF oHttpSession:OpenRequest("GET", "/agrotraza/src/api/Consulta_Tipo_Envase", INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION)
IF oHttpSession:SendRequest(NULL_STRING, PTR(_CAST, cRequest), SLen(cRequest))
cResponse:= oHttpSession:GetResponse()
InfoBox{SELF, "1.Response", cResponse}:Show()
ELSE
WarningBox{SELF, "1.Error.1", oHttpSession:ErrorMsg}:Show()
ENDIF
oHttpSession:CloseRequest()
ELSE
WarningBox{SELF, "1.Error.2", oHttpSession:ErrorMsg}:Show()
ENDIF
oHttpSession:CloseRemote()
oHttpSession:= NULL_OBJECT
ELSE
WarningBox{SELF, "1.Error.3", oHttpSession:ErrorMsg}:Show()
ENDIF

Option 2
oHttpSession:= CHttp{"SENASA.APIREST", 443}
IF oHttpSession:ConnectRemote("https://test.senasa.gov.ar")
IF oHttpSession:OpenRequest("GET", "/agrotraza/src/api/Consulta_Tipo_Envase", INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION + INTERNET_FLAG_SECURE)
IF oHttpSession:SendRequest(NULL_STRING, PTR(_CAST, cRequest), SLen(cRequest))
cResponse:= oHttpSession:GetResponse()
InfoBox{SELF, "2.Response", cResponse}:Show()
ELSE
WarningBox{SELF, "2.Error.1", oHttpSession:ErrorMsg}:Show()
ENDIF
oHttpSession:CloseRequest()
ELSE
WarningBox{SELF, "2.Error.2", oHttpSession:ErrorMsg}:Show()
ENDIF
oHttpSession:CloseRemote()
oHttpSession:= NULL_OBJECT
ELSE
WarningBox{SELF, "2.Error.3", oHttpSession:ErrorMsg}:Show()
ENDIF

Option 3
oHttpSession:= CHttp{"SENASA.APIREST"}
IF oHttpSession:ConnectRemote("test.senasa.gov.ar")
IF oHttpSession:OpenRequest("GET", "/agrotraza/src/api/Consulta_Tipo_Envase", INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION)
IF oHttpSession:SendRequest(NULL_STRING, PTR(_CAST, cRequest), SLen(cRequest))
cResponse:= oHttpSession:GetResponse()
InfoBox{SELF, "3.Response", cResponse}:Show()
ELSE
WarningBox{SELF, "3.Error.1", oHttpSession:ErrorMsg}:Show()
ENDIF
oHttpSession:CloseRequest()
ELSE
WarningBox{SELF, "3.Error.2", oHttpSession:ErrorMsg}:Show()
ENDIF
oHttpSession:CloseRemote()
oHttpSession:= NULL_OBJECT
ELSE
WarningBox{SELF, "3.Error.3", oHttpSession:ErrorMsg}:Show()
ENDIF

Option 4
oHttpSession:= CHttp{"SENASA.APIREST", 443}
IF oHttpSession:ConnectRemote("test.senasa.gov.ar")
IF oHttpSession:OpenRequest("GET", "/agrotraza/src/api/Consulta_Tipo_Envase", INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION + INTERNET_FLAG_SECURE)
IF oHttpSession:SendRequest(NULL_STRING, PTR(_CAST, cRequest), SLen(cRequest))
cResponse:= oHttpSession:GetResponse()
InfoBox{SELF, "4.Response", cResponse}:Show()
ELSE
WarningBox{SELF, "4.Error.1", oHttpSession:ErrorMsg}:Show()
ENDIF
oHttpSession:CloseRequest()
ELSE
WarningBox{SELF, "4.Error.2", oHttpSession:ErrorMsg}:Show()
ENDIF
oHttpSession:CloseRemote()
oHttpSession:= NULL_OBJECT
ELSE
WarningBox{SELF, "4.Error.3", oHttpSession:ErrorMsg}:Show()
ENDIF

Option 5
oHttpSession:= CHttp{"SENASA.APIREST"}
IF oHttpSession:ConnectRemote("http://test.senasa.gov.ar")
cResponse:= oHttpSession:GetDocumentByURL("http://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD")
InfoBox{SELF, "5.Response", cResponse}:Show()
ELSE
WarningBox{SELF, "5.Error.1", oHttpSession:ErrorMsg}:Show()
ENDIF
oHttpSession:CloseRemote()
oHttpSession:= NULL_OBJECT

Option 6
oHttpSession:= CHttp{"SENASA.APIREST", 443}
IF oHttpSession:ConnectRemote("https://test.senasa.gov.ar")
cResponse:= oHttpSession:GetDocumentByURL("https://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD")
InfoBox{SELF, "6.Response", cResponse}:Show()
ELSE
WarningBox{SELF, "6.Error.1", oHttpSession:ErrorMsg}:Show()
ENDIF
oHttpSession:CloseRemote()
oHttpSession:= NULL_OBJECT

Option 7
oHttpSession:= CHttp{"SENASA.APIREST"}
IF oHttpSession:ConnectRemote("test.senasa.gov.ar")
cResponse:= oHttpSession:GetDocumentByURL("test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD")
InfoBox{SELF, "7.Response", cResponse}:Show()
ELSE
WarningBox{SELF, "7.Error.1", oHttpSession:ErrorMsg}:Show()
ENDIF
oHttpSession:CloseRemote()
oHttpSession:= NULL_OBJECT

Option 8
oHttpSession:= CHttp{"SENASA.APIREST", 443}
IF oHttpSession:ConnectRemote("test.senasa.gov.ar")
cResponse:= oHttpSession:GetDocumentByURL("test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD")
InfoBox{SELF, "8.Response", cResponse}:Show()
ELSE
WarningBox{SELF, "8.Error.1", oHttpSession:ErrorMsg}:Show()
ENDIF
oHttpSession:CloseRemote()
oHttpSession:= NULL_OBJECT

Can any help me?
Regards.
Sebastián

D.J.W. van Kooten

unread,
Dec 24, 2021, 8:18:07 PM12/24/21
to
Replying on message of Fri, 24 Dec 2021 07:02:23 -0800 (PST) from
Sebastián BASSANO:


Hello Sebastián

>Hi, i'm trying to consume API REST from VO.
>For example:
>
>https://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD
>
>returns
>
>["Error de autenticaci\u00f3n (2) USER"]
>
>but from VO i always get empty response.


We've had some trouble REST API's (Sending XML) as well, in the X#
forum I asked this question:

https://www.xsharp.eu/forum/public-product/659-rest-service-does-not-work#4634

I don't recall all details but the main problem eventually was that
from VO a user name was not used somehow and when the password was
added directly before the xml (extra key-value-pair in the POST body),
something like this, it worked:

secret=123456&xml= <Root> etc.

Not sure if this helps you but maybe it's eventually the
authentication that fails so the result is empty. We got a test URL
which did not require a login and this returned the right values so we
knew the authentication was the problem.

If you would use an X# based DLL, which you can call from VO, you will
have more logical (.Net) code and many more samples and you will
probably solve it faster.

Dick

Sebastián BASSANO

unread,
Dec 26, 2021, 11:17:06 AM12/26/21
to
Thanks Dick.
I'll move to C# and call the code from VO as i do in other oportunities when i got stucked with VO.

Sebastián
Reply all
Reply to author
Forward
0 new messages