GetJWTToken
PowerScript function
Description
Gets the JWT token using the POST method.
Applies to
RESTClient objects
Syntax
|
1 |
objectname.GetJWTToken (string urlName, string data, ref string token) |
|
Argument |
Description |
|---|---|
|
objectname |
The name of the RESTClient object from which you want to |
|
urlName |
A string value specifying the URL. |
|
data |
A string value specifying the data to send. If the user sets the encoding charset in the Content-Type |
|
token |
The server response which contains the access If RESTClient failed to send request or server provides no |
Return value
Integer. Returns 1 if the function succeeds and a negative value if
an error occurs. If any argument’s value is null, the method returns
null.
1 — Success
-1 — General error
-2 — Invalid URL
-3 — Cannot connect to the Internet
-4 — Timeout
-5 — Failed to get token.
-7 — Failed to decompress data
-14 — Code conversion failed
-15 — Unsupported character set
Example 1
The following code example gets the data that requires JWT token
authentication.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
String ls_P028_JWTToken Integer li_P028_GetJWTTokenReturn RestClient lrc_P028 lrc_P028 = Create RestClient lrc_P028.SetRequestHeaders( "Content-Type:application/json;charset=UTF-8~r~nAccept-Encoding:gzip" ) //Sets the request header //Gets the JWT token. The second parameter provides the value according to the token server request. li_P028_GetJWTTokenReturn=lrc_P028.GetJWTToken("https://demo.appeon.com/pb/jwt/HSExample/api/values/GetToken", '{"Username":"user1","Password":"password1"}', ls_P028_JWTToken) If li_P028_GetJWTTokenReturn = 1 Then //Sets the JWT token lrc_P028.SetJwtToken( ls_P028_JWTToken) //Retrieves data for dw_Data lrc_P028.retrieve( dw_Data, "https://demo.appeon.com/pb/jwt/HSExample/api/department/retrieve") Else //Prints the GetJWTToken error message if any End If |
Example 2
The following code example gets the data that requires JWT token
authentication.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
String ls_P028_JWTToken Integer li_P028_GetJWTTokenReturn JsonPackage ljpk_JWTINF ljpk_JWTINF =Create JsonPackage RestClient lrc_P028 lrc_P028 = Create RestClient lrc_P028.SetRequestHeaders( "Content-Type:application/json;charset=UTF-8~r~nAccept-Encoding:gzip" ) //Sets the request header //Gets the JWT token. The second parameter provides the value according to the token server request. li_P028_GetJWTTokenReturn=lrc_P028.GetJWTToken("https://demo.appeon.com/pb/jwt/HSExample/api/values/Authenticate", '{"Username":"user1","Password":"password1"}', ls_P028_JWTToken) If li_P028_GetJWTTokenReturn = 1 Then //If the token server returns the token as well as other information, gets the token first and then provides it to RestClient //in this example, the token server returns a JSON string which contains token, therefore, gets the token via the following scripts ljpk_JWTINF.Loadstring( ls_P028_JWTToken) If ljpk_JWTINF.ContainsKey( "token" ) Then ls_P028_JWTToken = ljpk_JWTINF.GetValueString( "token" ) End If //Sets the JWT token lrc_P028.SetJwtToken( ls_P028_JWTToken) //Retrieves data for dw_Data lrc_P028.retrieve( dw_Data, "https://demo.appeon.com/pb/jwt/HSExample/api/department/retrieve") Else //Prints the GetJWTToken error message if any End If |
See also