Python

Features ›› Authentication ›› loginStaff ›› Sample Code ››
Parent Previous Next

Login Staff


We will first import "request" and "json" module, as we need those module for calling the API

Then, we will import our own url from a file called functions.py, which can be referred to in the "Common Stuff" section linked at the bottom.



Next, we create a function loginStaff

Inside the function, we will create the input variables.




Then we build the header and content object.




Then, we will create the final url, where we will use the url() function to get the API url, and append the headerObj t and contentObj o the API url.

We will then post the final_url and store the server response in the variable "response".

The GlobalErrorID is then retrieved and stored in variable "errorCode".



If the errorCode is '010000', it means that there is no error, and we will display 'the result.

If the errorCode is '010041', it means that the OTP provided has expired. We will then display 'OTP has expired. You will be receiving a SMS'.

Else, we will display the ErrorText.




Entire Code:


import requests, json

from functions import url


def loginStaff():

   OTP = '', #not used

   PIN = '', #not used

   serviceName = 'loginStaff',

   userID = '' #not used


   username = "alan"

   password = "123456"

   application = "Teller"


   headerObj = {

                           'Header': {

                           'serviceName': serviceName,

                           'userID': userID,

                           'PIN': PIN,

                           'OTP': OTP

                           }

                           }

   

   contentObj = {

                       'Content': {

                       'username': username,

                       'password': password,

                       'application': application

                       }

                       }


   final_url="{0}?Header={1}&Content={2}&ConsumerID=Teller".format(url(),json.dumps(headerObj),json.dumps(contentObj))

   response = requests.post(final_url)


   serviceRespHeader = response.json()['Content']['ServiceResponse']['ServiceRespHeader']

   errorCode = serviceRespHeader['GlobalErrorID']


   if errorCode == '010000':

       StaffLoginAuthenticateResponseObj = response.json()['Content']['ServiceResponse']['Staff_Login_Authenticate-Response']

       print('Firstname: {}'.format(StaffLoginAuthenticateResponseObj['Firstname']))

       print('BankName: {}'.format(StaffLoginAuthenticateResponseObj['BankName']))

       print('Usertype: {}'.format(StaffLoginAuthenticateResponseObj['Usertype']))

       print('BankBranch: {}'.format(StaffLoginAuthenticateResponseObj['BankBranch']))

       print('BankLogoLocation: {}'.format(StaffLoginAuthenticateResponseObj['BankLogoLocation']))

       print('LastLoginTimestamp: {}'.format(StaffLoginAuthenticateResponseObj['LastLoginTimestamp']))

       

       print('BankAddress: {}'.format(StaffLoginAuthenticateResponseObj['BankAddress']))

       print('Lastname: {}'.format(StaffLoginAuthenticateResponseObj['Lastname']))

       print('BaseCurrency: {}'.format(StaffLoginAuthenticateResponseObj['BaseCurrency']))

       print('BankID: {}'.format(StaffLoginAuthenticateResponseObj['BankID']))

       print('BIC: {}'.format(StaffLoginAuthenticateResponseObj['BIC']))


   elif errorCode == '010041':

       print("OTP has expired.\nYou will receiving a SMS")


   else:

       print(serviceRespHeader['ErrorText'])


loginStaff()

   


Download


Go to Common Stuff Section

Created with the Personal Edition of HelpNDoc: Create help files for the Qt Help Framework