Sap BO RestFul Web Servis ile kullanıcı listesi çıkarılması

(Sap BO user list exctraction with Restful Web Service)

Sap Business Objects ortamında kullanıcı listesi ResftFul Web Service SDK (Python dilinde) almak için aşağıdaki kod kullanılabilir.

#!/usr/bin/python
# -*- coding: utf-8 -*-



import sys
reload(sys)
sys.setdefaultencoding('utf8')



import requests, json, re

baseurl = 'http://hostname_ip:port/biprws' # change hostname ip port, example: 192.168.56.101:6405

headerJson = {'accept': 'application/json'}

r = requests.get(baseurl+'/logon/long', headers=headerJson)

headerJson2 = {'accept': 'application/json', 'content-type': 'application/json'}

postDataJson = '{"userName":"Administrator","password":"PassWD","auth":"secEnterprise"}' # change password

r = requests.post(baseurl+'/logon/long', headers=headerJson2, data=postDataJson)

sapBoLogonToken = '"' + json.loads(r.text)['logonToken'] + '"'

headerJson3 = {'accept': 'application/json', 'X-SAP-LogonToken': sapBoLogonToken}



looperPage = 1
looperPageSize = 50

r = requests.get(baseurl+'/v1/users?page='+str(looperPage)+'&pagesize='+str(looperPageSize), headers=headerJson3)
parsedJson = json.loads(r.text)

userList = []
while len(parsedJson["entries"]) == looperPageSize:
  userList.extend( parsedJson["entries"] )
  looperPage += 1
  r = requests.get(baseurl+'/v1/users?page='+str(looperPage)+'&pagesize='+str(looperPageSize), headers=headerJson3)
  parsedJson = json.loads(r.text)



# rest log off
headerJson4 = {'accept': 'application/json', 'content-type': 'application/json', 'X-SAP-LogonToken': sapBoLogonToken}
r = requests.post(baseurl+'/logoff', headers=headerJson4)



f = open('./user_list.csv','w')

f.write("user_id,user_name,user_fullname\n")
for uli in userList:
  f.write(uli["id"]+","+uli["name"]+","+uli["fullname"]+"\n")

"""
# maybe needed for some users detection
f.write("user_id,user_name,user_name_length,user_fullname,user_fullname_length,reg_exp_flag\n")
for uli in userList:
  if ( len(re.findall("[a-zA-Z]{2}[0-9]{4}",uli["name"])) > 0 ):
    reg_exp_flag = "1"
  else:
    reg_exp_flag = "0"
  f.write(uli["id"]+","+uli["name"]+","+str(len(uli["name"]))+","+uli["fullname"]+","+str(len(uli["fullname"]))+","+reg_exp_flag+"\n")
# reg_exp_flag=1, user_fullname_length<>0, user_name_length=6
"""

f.close()

Dosya olarak indirmek için: re_cmc_user_list.py

Bir cevap yazın