Skip to content

Sign in

Developer From Jokela edited this page Nov 10, 2020 · 3 revisions

To sign in, run function login from the SDK. Example:

from wilmasdk.sdk import WilmaSDK

sdk = WilmaSDK()

# Set server url
sdk.setWilmaServer('https://tuusula.inschool.fi')

# Set username, password and apikey
result = sdk.login('username', 'password', 'apikey')

if result.is_error():
    if result.get_wilma_error() is not None:
        print(result.get_wilma_error()['message'])
        print("--> "+result.get_wilma_error()['description'])
    else:
        print(result.get_exception())
else:
    print("SID: "+result.session)
    # TODO Store result.session (token) somewhere safe, this is the authentication token.
    print("Login successful!")
    # If this boolean is true, you should handle roles. More about roles down below the wiki page
    print("Roles required: "+str(result.roleSelectionRequired))
    print("Homepage: ")
    # Homepage is accessible from login response
    print(result.homepage)

For Sign in, you need your own API Key from Visma! Get in touch with them to get one via their website.

Sign in response returns you:

  • User's session (result.session), which you should store safely, as it's access key to user's account
  • User's Homepage (result.homepage)
  • Does user's account require you to choose a role (result.roleSelectionRequired), when this boolean is true, you should handle roles like mentioned down below

Sign in using token

If you've already signed in, and have token stored somewhere, call loginUsingSessionId.

Example: result = sdk.loginUsingSessionId('YOUR_TOKEN') That will return HomepageResult.

Token renewing

When token expires, SDK will throw an exception wilmasdk.exception.exceptions.TokenExpiredException. That means that you'll have to run basic login to obtain new token.

Clone this wiki locally