- Miller Rhodes
- PowerBuilder
- Thursday, 2 June 2022 07:13 PM UTC
Currently, we are using the OauthClient object to request a token and then use that token to get the data using the RequestResource function.
Thanks to a lot of the posts I have seen here, I was able to put this together and it works quite well.
Until... It gets into Citrix.
In the code example below , this line works fine : ll_Return = loac_Client.AccessToken( ltr_Request, ltr_Response )
but this line returns a -1 : ll_return = loac_Client.RequestResource( loar_Request, lrr_Response )
I am wondering if anyone else has had difficulties when they get into Citrix and is there a way to overcome it?
//The complete code example is as below:
OAuthClient loac_Client
TokenRequest ltr_Request
TokenResponse ltr_Response
OAuthRequest loar_Request
ResourceResponse lrr_Response
String ls_AccessToken, ls_parameter_string
String ls_Body, ls_type, ls_description, ls_uri, ls_state, ls_token_body
Long ll_return, ll_return2, ll_ret, ll_ret2
Integer li_rtn
Blob lblb_data
String ls_encode_scope
loac_Client = Create OAuthClient
date ld_startdate, ld_end_date
CoderObject lnv_CoderObject
lnv_CoderObject = Create CoderObject
lblb_data = Blob(is_scope, EncodingANSI!)
ls_encode_scope = lnv_CoderObject.UrlEncode(lblb_data)
ls_parameter_string = '?equipmentInitial=' + is_equipment_initial
ls_parameter_string += '&equipmentNumber=' + string(il_equipment_number)
ls_parameter_string += '&startDate=' + string(idt_start_datetime, 'yyyy-mm-dd')
ls_parameter_string += '&endDate=' + string(idt_end_datetime, 'yyyy-mm-dd' )
ltr_Request.SetHeader('Content-Type', 'application/x-www-form-urlencoded')
ltr_Request.Method = "POST"
ltr_Request.tokenlocation = is_tokenlocation
ltr_Request.secureprotocol = 0
ltr_Request.clientid = is_clientid
ltr_Request.clientsecret = is_clientsecret
ltr_Request.scope = ls_encode_scope
ltr_Request.granttype = "client_credentials"
ltr_Request.timeout = 120
loar_Request.timeout = 120
Setpointer(hourglass!)
ll_Return = loac_Client.AccessToken( ltr_Request, ltr_Response )
If ll_Return = 1 and ltr_Response.GetStatusCode () = 200 Then
ll_Return = ltr_Response.GetBody(ls_token_body)
If ll_Return = 1 Then
ls_AccessToken = ltr_Response.GetAccessToken()
messagebox( ls_AccessToken, 'token')
//Step 2: Get the RESTful server resource.
loar_Request.Method = "GET"
loar_Request.Url = "https://elevate-k8s-dev.gmas.io/zones/movement-data-api/api/v1/MovementData"
loar_Request.Url += ls_parameter_string
ll_ret = loar_Request.SetAccessToken( ls_AccessToken )
messagebox(string(ll_ret), 'll_ret')
ll_return = loac_Client.RequestResource( loar_Request, lrr_Response )
If ll_Return <> 1 or lrr_Response.GetStatusCode () <> 200 Then
string(lrr_Response.GetStatusCode () ) )
ll_return = loac_Client.RequestResource( loar_Request, lrr_Response )
End If
If ll_Return = 1 and lrr_Response.GetStatusCode () = 200 Then
ll_return2 = lrr_Response.GetBody(ls_Body)
If ll_return2 < 1 then
MessageBox( "Failed to extract data from the API", "Return :" + String ( ll_return ) + "~r~n" + lrr_Response.GetStatusText() )
return -1
End If
string ls_JsonPackage, ls_Error
long ll_RowCount
JsonParser lnv_JsonParser
lnv_JsonParser = Create JsonParser
ls_Error = lnv_JsonParser.LoadString(ls_Body)
if Len(ls_Error) > 0 then
MessageBox("Error", ls_Error)
return -1
end if
ll_RowCount = dw_cp_movement.ImportJson(ls_Body)
dw_cp_movement.sort()
Else
MessageBox( "Request resource Failed", "Return :" + String ( ll_return ) + "~r~n" + lrr_Response.GetStatusText() )
return -1
End If
End If
Else
ll_Return = ltr_Response.GetTokenError(ls_type, ls_description, ls_uri, ls_state)
MessageBox( "AccessToken Falied", "Return :" + String ( ll_return ) + "~r~n" + ls_description )
return -1
End If
return 1
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.