Skip to content

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.

Structure

The SDK essentially provides you the information from API, does the HTTP, JSON conversion, error handling, etc.

What do I have to do myself?

  • Store Session ID (or token, whatever you like to call it), and renew it when needed

Example request

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. Function get_exception returns only exceptions which are caused typically by: Networking errors, library's internal errors and parsing issues.

How to get response?

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

Clone this wiki locally