Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
abdo
Participant
Jump to solution

Retrieve policy details using api

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

 

0 Kudos
1 Solution

Accepted Solutions
PhoneBoy
Admin
Admin
It's a little more complicated than that.
Here's a couple of Open Source projects we have that do this (in Python), one for export/import, the other to render in HTML/JSON:
https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/Python-tool-for-exporting-importi...
https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/Show-Package-Tool-to-visualize-a-...

View solution in original post

0 Kudos
2 Replies
Will_H
Contributor
Also interested..
0 Kudos
PhoneBoy
Admin
Admin
It's a little more complicated than that.
Here's a couple of Open Source projects we have that do this (in Python), one for export/import, the other to render in HTML/JSON:
https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/Python-tool-for-exporting-importi...
https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/Show-Package-Tool-to-visualize-a-...
0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events