use xbase to communicate with a rest API
Posted: Thu Jul 07, 2022 8:45 am
Hello!
I'm trying to communicate with a rest API.
I have no experience with this type of procedure.
I need to do this in xbase:
must get this response:
My xBase code is this. but it does not work. Someone with experience in this can help.
Note :
the user and the pass are authentic to be able to test.
It is a test server.
any tips would be important
I'm trying to communicate with a rest API.
I have no experience with this type of procedure.
I need to do this in xbase:
Code: Select all
Request:
1POST https://dcn-solution.saphety.com/Dcn.Sandbox.WebApi/api/Account/GetToken
2Content-Type: application/json
3
4{
5 "Username": "comercial@algarbytes.pt",
6 "Password": "ab917007041**"
7}
Code: Select all
Response:
1HTTP/1.1 200 OK
2Content-Type: application/json
3
4{
5 "CorrelationId": "58b6f620-6167-4506-aec7-df4de92ecfa1",
6 "IsValid": true,
7 "Errors": [],
8 "Data": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiJjb21lcmNpYWxAYWxnYXJieXRlcy5wdCIsInVuaXF1ZV9uYW1lIjoiY29tZXJjaWFsQGFsZ2FyYnl0ZXMucHQiLCJzeXN0ZW1fYWRtaW4iOiJGYWxzZSIsInNlc3Npb25faWQiOiJhODZkODdhOS1mZDA5LTRhNjktOGIyMC1mZTIwODYyYTY5OWIiLCJjcCI6ImNvbWVyY2lhbEBhbGdhcmJ5dGVzLnB0IiwicmwiOiJEZXZlbG9wZXIiLCJuYmYiOjE2NTcyMDgyMDgsImV4cCI6MTY1NzIzNzAwOCwiaWF0IjoxNjU3MjA4MTQ4LCJpc3MiOiJodHRwczovL3d3dy5zYXBoZXR5LmNvbS8iLCJhdWQiOiJodHRwczovL3d3dy5zYXBoZXR5LmNvbS9EY25TYW5kYm94In0.QX-Bc7Qfm4mmYCheZhyFvV9K0rQdy4yUs0JFJ0H6X0s"
9}
Code: Select all
Function Teste_SAPHETY()
LOCAL oPost
LOCAL cResult
// Process the SOAP request
oPost := HttpClient():new( "https://dcn-solution.saphety.com/Dcn.Sandbox.WebApi/api/Account/GetToken" )
oPost:httpRequest:setParameter( "Username", "comercial@algarbytes.pt" )
oPost:httpRequest:setParameter( "Password", "ab917007041**" )
oPost:httpRequest:setContentType("application/json")
oPost:httpRequest:setMethod( "POST" )
cResult := oPost:send()
Sleep(50)
IF oPost:getStatusCode() == 200
Msgbox( "ok" )
Else
MsgBox( "failed: " + oPost:httpResponse:statusText, 'Falhou!' )
Endif
IF oPost:getStatusCode() != 200
IF oPost:getStatusCode() ==-1
MsgBox( Var2Char(oPost:getLastError()) + Chr(13) + Var2Char(oPost:getLastMessage()), "Non HTTP protocol error:" )
ELSE
MsgBox( Var2Char(oPost:getLastError()) + Chr(13) + Var2Char(oPost:getLastMessage()), "HTTP protocol error:" )
ENDIF
ENDIF
MsgBox( cResult, 'Token' )
RETURN NIL
the user and the pass are authentic to be able to test.
It is a test server.
any tips would be important