hi everybody,
My script below do not get required token as it return error -21. Even I have commented out the "secureprotocal" or set it to lower version, it's still not work. Please help
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, ls_rtn
Long ll_return, ll_rtn
loac_Client = Create OAuthClient
//Step 1: Get the RESTful server access token.
//The following line is fake code. Replace it with settings
//from your OAuth 2.0 authorization server provider.
ltr_Request.tokenlocation = "https://preprod-api.myinvois.hasil.gov.my/connect/token"
ltr_Request.Method = "POST"
//ltr_Request.secureprotocol = 0
ltr_Request.clientid = "93e....ae"
ltr_Request.clientsecret = "3ed....f4a"
ltr_Request.granttype = "client_credentials"
ltr_Request.scope = "InvoicingAPI"
ltr_Request.ClearHeaders()
//ltr_Request.SetHeader("User-Agent", "PostmanRuntime/7.37.3")
//ltr_Request.SetHeader("Accept", "*/*")
//ltr_Request.SetHeader("Postman-Token", "00fd85e7-38bf-408a-a846-aaa073436928")
//ltr_Request.SetHeader("Host", "preprod-api.myinvois.hasil.gov.my")
//ltr_Request.SetHeader("Accept-Encoding", "gzip, deflate, br")
//ltr_Request.SetHeader("Connection", "keep-alive")
//ltr_Request.SetHeader("Content-Type", "application/json;charset=UTF-8" ) //"application/x-www-form-urlencoded")
ltr_Request.SetHeader("Content-Length", "2048") //"146")
ll_Return = loac_Client.AccessToken( ltr_Request, ltr_Response )
If ll_Return = 1 Then
ll_rtn = ltr_Response.GetStatusCode ()
ls_rtn = ltr_Response.getstatustext( )
ll_Return = ltr_Response.GetBody(ls_Body)
If ll_Return = 1 Then
ls_AccessToken = ltr_Response.GetAccessToken()
IF ls_AccessToken = '' THEN RETURN -1;
//Step 2: Get the RESTful server resource.
loar_Request.Method = "GET"
//The following line is fake code. Replace it with settings
//from your OAuth 2.0 authorization server provider.
loar_Request.Url = "https://preprod-api.myinvois.hasil.gov.my/api/v1.0/documenttypes" //"https://xxx.xxx.xxx/order/getall"
loar_Request.SetAccessToken( ls_AccessToken )
ll_Return = loac_Client.RequestResource( loar_Request, lrr_Response )
If ll_Return = 1 Then
ll_Return = lrr_Response.GetBody(ls_Body)
If ll_Return = 1 Then
MessageBox ( "Resource", ls_Body )
End If
Else
MessageBox( "Requestresource Falied", "Return :" + String ( ll_return ) + "~r~n" + lrr_Response.GetStatusText() )
End If
End If
Else
ll_rtn = 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 )
regards,
Ong
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, ls_rtn
Long ll_return, ll_rtn
loac_Client = Create OAuthClient
//Step 1: Get the RESTful server access token.
//The following line is fake code. Replace it with settings
//from your OAuth 2.0 authorization server provider.
ltr_Request.tokenlocation = "https://pr...t/token"
ltr_Request.Method = "POST"
//ltr_Request.secureprotocol = 0
ltr_Request.clientid = "93e....ae"
ltr_Request.clientsecret = "3ed....f4a"
ltr_Request.granttype = "client_credentials"
ltr_Request.scope = "InvoicingAPI"
ltr_Request.ClearHeaders()
//ltr_Request.SetHeader("User-Agent", "PostmanRuntime/7.37.3")
//ltr_Request.SetHeader("Accept", "*/*")
//ltr_Request.SetHeader("Postman-Token", "00fd85e7-38bf-408a-a846-aaa073436928")
//ltr_Request.SetHeader("Host", "pr...")
//ltr_Request.SetHeader("Accept-Encoding", "gzip, deflate, br")
//ltr_Request.SetHeader("Connection", "keep-alive")
//ltr_Request.SetHeader("Content-Type", "application/json;charset=UTF-8" ) //"application/x-www-form-urlencoded")
ltr_Request.SetHeader("Content-Length", "2048") //"146")
ll_Return = loac_Client.AccessToken( ltr_Request, ltr_Response )
If ll_Return = 1 Then
ll_rtn = ltr_Response.GetStatusCode ()
ls_rtn = ltr_Response.getstatustext( )
ll_Return = ltr_Response.GetBody(ls_Body)
If ll_Return = 1 Then
ls_AccessToken = ltr_Response.GetAccessToken()
IF ls_AccessToken = '' THEN RETURN -1;
//Step 2: Get the RESTful server resource.
loar_Request.Method = "GET"
//The following line is fake code. Replace it with settings
//from your OAuth 2.0 authorization server provider.
loar_Request.Url = "https://p.../documenttypes" //"https://xxx.xxx.xxx/order/getall"
loar_Request.SetAccessToken( ls_AccessToken )
ll_Return = loac_Client.RequestResource( loar_Request, lrr_Response )
If ll_Return = 1 Then
ll_Return = lrr_Response.GetBody(ls_Body)
If ll_Return = 1 Then
MessageBox ( "Resource", ls_Body )
End If
Else
MessageBox( "Requestresource Falied", "Return :" + String ( ll_return ) + "~r~n" + lrr_Response.GetStatusText() )
End If
End If
Else
ll_rtn = 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 )