Python

Features ›› Customer ›› getCustomerDetails ›› Sample Code ››
Parent Previous Next

Get Customer Details



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

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

We will also import a reference data API 'getCustomerTypes' as one of the output is customerType, and we want to show customerTypeName.

The Reference Data API can be referred under Reference Data Sub-Menu



Next, we create a function getCustomerDetails

Inside the function, we will create the input variables.



Then we build the header object.



Then, we will create the final url, where we will use the url() function to get the API url, and append the headerObj and contentObj to 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

from getCustomerTypes import getCustomerTypes


def getCustomerDetails():

   #Header

   serviceName = 'getCustomerDetails'

   userID = 'bobsmith1'

   PIN = '123456'

   OTP = '123456'

   

   headerObj = {

                       'Header': {

                       'serviceName': serviceName,

                       'userID': userID,

                       'PIN': PIN,

                       'OTP': OTP

                       }

                       }

   final_url="{0}?Header={1}".format(url(),json.dumps(headerObj))

   response = requests.post(final_url)

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

   errorCode = serviceRespHeader['GlobalErrorID']

   

   if errorCode == '010000':

       CDMCustomer = response.json()['Content']['ServiceResponse']['CDMCustomer']

       print('Date of Birth: {}'.format(CDMCustomer['dateOfBirth']))

       print('Tax Identifier: {}'.format(CDMCustomer['taxIdentifier']))

       print('Local Number: {}'.format(CDMCustomer['phone']['localNumber']))

       print('Area Code: {}'.format(CDMCustomer['phone']['areaCode']))

       print('Country Code: {}'.format(CDMCustomer['phone']['countryCode']))

       print('Certificate Issuer: {}'.format(CDMCustomer['certificate']['certificateIssuer']))

       print('Certificate No.: {}'.format(CDMCustomer['certificate']['certificateNo']))

       print('Certificate Expiry Date: {}'.format(CDMCustomer['certificate']['certificateExpiryDate']))

       print('Certificate Type: {}'.format(CDMCustomer['certificate']['certificateType']))

       print('Postal Code: {}'.format(CDMCustomer['address']['postalCode']))

       print('Street Address 1: {}'.format(CDMCustomer['address']['streetAddress1']))

       print('Street Address 2: {}'.format(CDMCustomer['address']['streetAddress2']))

       print('State: {}'.format(CDMCustomer['address']['state']))

       print('Country: {}'.format(CDMCustomer['address']['country']))

       print('City: {}'.format(CDMCustomer['address']['city']))

       print('Phone Number: {}'.format(CDMCustomer['cellphone']['phoneNumber']))

       print('Country Code: {}'.format(CDMCustomer['cellphone']['countryCode']))

       print('Family Name: {}'.format(CDMCustomer['familyName']))

       print('Registration Date: {}'.format(CDMCustomer['maintenacehistory']['registrationDate']))

       print('Last Maintenance Teller: {}'.format(CDMCustomer['maintenacehistory']['lastMaintenanceTellerId']))

       print('Given Name: {}'.format(CDMCustomer['givenName']))

       print('Customer ID: {}'.format(CDMCustomer['customer']['customerID']))

       print('isMerchant: {}'.format(CDMCustomer['profile']['isMerchant']))

       print('Occupation: {}'.format(CDMCustomer['profile']['occupation']))

       print('Fax: {}'.format(CDMCustomer['profile']['fax']))

       print('Nationality: {}'.format(CDMCustomer['profile']['nationality']))

       print('Customer Type: {}'.format(getCustomerTypes(CDMCustomer['profile']['customerType'])))

       print('Email: {}'.format(CDMCustomer['profile']['email']))

       print('Ethnic Group: {}'.format(CDMCustomer['profile']['ethnicGroup']))

       print('Gender: {}'.format(CDMCustomer['profile']['gender']))

       print('isBillingOrg: {}'.format(CDMCustomer['profile']['isBillingOrg']))

       print('Bank ID: {}'.format(CDMCustomer['profile']['bankID']))

   elif errorCode == '010041':

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

   else:

       print(serviceRespHeader['ErrorText'])

           

getCustomerDetails()


Download


Go to Common Stuff Section

Created with the Personal Edition of HelpNDoc: Easily create Help documents