- Pepe Cuenca
- PowerBuilder
- Tuesday, 11 January 2022 03:43 PM UTC
Hi all,
I'm trying to consume a Rest API to get an authentication token.
I have no problemems getting the token on Postman with this configuration:
But I cant't do it in PB 2021 with OauthClient, it throws me a -1 error code (tried also with httpclient, but same result):
I'm using the code from the documentation, changing what I needed:
OAuthClient loac_Client
TokenRequest ltr_Request
TokenResponse ltr_Response
OAuthRequest loar_Request
ResourceResponse lrr_Response
String ls_AccessToken
String ls_Body, ls_type, ls_description, ls_uri, ls_state
Long ll_return
loac_Client = Create OAuthClient
//Step 1: Get the RESTful server access token.
ltr_Request.ClearParams()
ltr_Request.tokenlocation = "https://amtrip.amfresh.com/i/connect/token"
ltr_Request.granttype = "client_credentials"
ltr_Request.Method = "POST"
ltr_Request.clientid = "ZZZZZZ"
ltr_Request.clientsecret = "XXXXXX"
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_Body)
If ll_Return = 1 Then
ls_AccessToken = ltr_Response.GetAccessToken()
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 )
End If
If IsValid ( loac_Client ) Then DesTroy ( loac_Client )
return ls_accessToken
Could anyone give me a hint on what I'm missing??
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.