Description
Creates a session.
Applies to
Syntax
applicationname.BeginSession ( )
Argument |
Description |
---|---|
applicationname |
The name of the application object for which you want to create a session |
Usage
Normally there is no need to call this function to create a session, because the session is automatically created when the application starts. You may want to execute this function to create a session, only when you have obtained the access token and you want the session to include the access token.
In order to execute this function successfully, the "Begin session by code" option must be selected in the Application painter's Properties view so that the session will not be created automatically, otherwise, this function will return -1 (indicating the session has already been created).
Return value
Integer.
Returns 0 if it succeeds and -1 if session already exists or if the current application is not an installable cloud app deployed with PowerServer.
Returns one of the following numbers if an error occurs:
-
220 -- General session error.
-
222 -- Cannot connect with the server when creating the session.
-
230 -- License errors.
-
240 -- Unauthorized.
Examples
Long ll_Return String ls_TokenType, ls_AccessToken, ls_Json JsonParser ljson_Parser ljson_Parser = Create JsonParser ls_Json = '{' +& ' "access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjM4OEQ0NEIxRDdBNkVFOUQxNTU0MDAzQUMzM0QzQzkzIiwidHlwIjoiYXQrand0In0.eyJuYmYiOjE2MTI0MDIxODUsImV4cCI6MTYxMjQwMjM2NSwiaXNzIjoiaHR0cHM6Ly9sb2NhbGhvc3Q6NTAwMSIsImNsaWVudF9pZCI6IllvdXJDbGllbnRJZFRoYXRDYW5Pbmx5UmVhZCIsInN1YiI6IlBBTkdDSFVHVUFOIiwiYXV0aF90aW1lIjoxNjEyNDAyMTg1LCJpZHAiOiJsb2NhbCIsImp0aSI6IjFDNEQ4NEFBODU0REYxODMwQkVGQTAwQTFBMjdFMDk0IiwiaWF0IjoxNjEyNDAyMTg1LCJzY29wZSI6WyJzY29wZS5yZWFkYWNjZXNzIl0sImFtciI6WyJjdXN0b20iXX0.DbJsip696O1HlTFjAmayohhHGEcjIQxJM7JICi9ho5MAv2Av4YjQOGgXrCNFhwqG4AFTf3hHwufGYXxzXI8tCYfn3F3ro36dd-0h_A-__5sBelZD0vr6nmWh8Uy-zoJenzsrnVEv8VHVNi2enuKH6SBe-Q59bn5A-Gbg6viNjv0S5HIaKuWeawExBH6uEAu28RlSlfG2bwWuCsyhYWOPIhNhYcZTbVD8ks0SFodGeGS-ZqNOVrOTKb9oqnhvYxnuNofJpjToZ8ZZdKyWiyJUhItpTQTyI3MsCHoVU4X101YTPrVMF_-OuPSwXm6QMl3QtI_6Hy_PeYHL-xz2-q3tog",' +& ' "expires_in": 3600,' +& ' "token_type": "Bearer",' +& ' "scope": "scope.readaccess"' +& '}' ljson_Parser.LoadString( ls_Json ) ls_TokenType = ljson_Parser.GetItemString( "/token_type" ) ls_AccessToken = ljson_Parser.GetItemString( "/access_token" ) ll_Return = Getapplication().SetHttpRequestHeader( "Authorization", ls_TokenType + " " + ls_AccessToken, True ) Try ll_return = Getapplication().Beginsession() If ll_return <> 0 Then Messagebox("Beginsession Failed: " + String(ll_return), Getapplication().GetHttpResponseStatusText()) End if Catch ( Throwable ex) MessageBox( "Throwable", ex.GetMessage()) End Try If IsValid ( ljson_Parser ) Then Destroy ( ljson_Parser )
See also