Retrieve extended account attributes using PBA API

Python is a powerful language that includes all tools required to interface with the PBA API. The following PBA 5.4 API example retrieves four custom attributes from an account if available. This generic approach can be used on any extended attribute.

All information about available methods in PBA public API, could be found in documentation: Public API Reference

Below you could find example of AccountDetailsGet_API method:

The line

server = xmlrpclib.ServerProxy('http://192.168.234.45:5224/RPC2')

defines the location of the PBA server. By default, it listens on port 5224. You need to make sure that this port is reachable from your source IP. Replace 198.168.234.45 with the correct IP address of your server.

import xmlrpclib
import base64
import sys

try:
   customer = input("Enter Parallels customer account number: ")
except Exception:
   print "No customer account entered"
   sys.exit(1);

server = xmlrpclib.ServerProxy('http://192.168.234.45:5224/RPC2')

p1 = {"Server":"BM","Method":"AccountDetailsGet_API","Params":[customer]}

try:
   Customer = (server.Execute(p1))
except Exception, err:
   print 'Fault code:', err.faultCode
   print 'Message :', base64.b64decode(err.faultString)
   sys.exit(2)

print "Customer: " , Customer['Result'][0][0]
print "Account: " , Customer['Result'][0][2]

p2 = {"Server":"BM", "Method":"GetObjAttrList_API","Params":[0,customer,0,""]}

try:
   Customer = (server.Execute(p2))
except Exception, err:
   print 'Fault code:', err.faultCode
   print 'Message :', base64.b64decode(err.faultString)
   sys.exit(3)

if Customer['Result'][0][1][1] :
   print "CPF: " , Customer['Result'][0][1][1]
if Customer['Result'][0][0][1] :
   print "CPNJ: ", Customer['Result'][0][0][1]
if Customer['Result'][0][4][1] :
   print "CLE: ", Customer['Result'][0][4][1]

# CPNJ: ['CPF', '585.816.358-06', 'PERS']
# {'Result': [[['CNPJ', '', 'COMP'], ['CPF', '585.816.358-06', 'PERS'], ['Complemento', '', 'COMP, PERS'], ['Bairro', 'wswsw', 'COMP, PERS'], ['CLE', '000000023232323', 'PERS, COMP']]]}

Resulting in output:

[root@pbalinfe01 parallels]# python retracct.py
Enter Parallels customer account number: 1000010
Customer: 1000010
Account: QATestCSD
CPF: 1
CPNJ: 113045999
CLE: 0
[root@pbalinfe01 parallels]#

Internal content