I am trying to write a script to retrieve all policy details of R80 using web services api. I used show-package command to retrieve all policy package details . Also i made details-level full to retrieve all possible info. I wonder if this call will retrieve all the information about the package and all it's objects ?
here is my python code
import requests, json
host = "" # hard code host
port = "" # hard code port
def api_call(ip_addr, port, command, json_payload, sid):
url = 'https://' + ip_addr + ':' + port + '/web_api/' + command
if sid == '':
request_headers = {'Content-Type' : 'application/json'}
else:
request_headers = {'Content-Type' : 'application/json', 'X-chkp-sid' : sid}
r = requests.post(url,data=json.dumps(json_payload), headers=request_headers)
return r.json()
def login(user,password):
payload = {'user':user, 'password' : password}
response = api_call(host, port, 'login',payload, '')
return response["sid"]
def retrieve_policy(username,password,package_name):
sid = login(username,password) #get sid after successful login to authenticate with
retrieve_policy_data = {'name' : package_name,'details-level' : 'full'} #I made details-level full to retieve all possible info
retrieve_policy_result = api_call(host, port,'show-package', retrieve_policy_data ,sid)
logout_result = api_call(host, port,"logout", {},sid) #logout
return retrieve_policy_result #all package details returned in json format