-
Notifications
You must be signed in to change notification settings - Fork 0
The basics (README before you continue)
Developer From Jokela edited this page Nov 9, 2020
·
3 revisions
Wilma's Python SDK requires an API Key from Visma, it doesn't work without that.
The SDK essentially provides you the information from API, does the HTTP, JSON conversion, error handling, etc.
- Store Session ID (or token, whatever you like to call it), and renew it when needed
Here's how basic Wilma SDK request looks like:
from wilmasdk.sdk import WilmaSDK
sdk = WilmaSDK() # <-- Initializing SDK
servers = sdk.getWilmaServers() # <-- Making request to fetch wilma servers
if servers.is_error(): # <-- Checking if any errors occurred
print(servers.get_exception()) # <-- Returns Exception class
if servers.get_wilma_error() is not None: # <-- If Wilma server error
print(servers.get_wilma_error()) # <-- Getting error as an dist object
else:
print(servers.get_wilma_servers()) # <-- Getting servers list
Every request is based on RequestResult
class, which contains functions like:
get_exception
is_error
get_response
However, errors are ErrorResult
class, which has in addition to RequestResult
's functions:
-
get_wilma_error
This returns Wilma server error. Wilma error is an error message returned by Wilma server. Functionget_exception
returns only exceptions which are caused typically by: Networking errors, library's internal errors and parsing issues.
Every request has its response in its special key. For example, if you're fetching user's homepage, its key is homepage
.
Code example:
print("Fetching homepage")
homepageResult = sdk.getHomepage()
if not homepageResult.is_error():
print(homepageResult.homepage)
At this point you're ready to continue