<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: python api script in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/python-api-script/m-p/168907#M7449</link>
    <description>&lt;P&gt;I wrote some scripts leveraging the SDK - like:&amp;nbsp;&lt;A href="https://github.com/leinadred/CP_IPS-Update-Monitoring4Nagios" target="_blank" rel="noopener"&gt;https://github.com/leinadred/CP_IPS-Update-Monitoring4Nagios&amp;nbsp;&lt;/A&gt;or &lt;A href="https://github.com/leinadred/py_cp-updatable-objects" target="_blank" rel="noopener"&gt;https://github.com/leinadred/py_cp-updatable-objects&lt;/A&gt;&lt;/P&gt;&lt;P&gt;difficult to say, without being able to see your script. but i think you went out of the "with" procedure, so SDK logged you out. As API is "opened" like a file, with is closing it (and logs off the connection) when leaving the file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So your "working procedures" will have to be inside of the "opened file"&lt;/P&gt;&lt;P&gt;in&amp;nbsp;&lt;A href="https://github.com/leinadred/py_cp-updatable-objects" target="_blank" rel="noopener"&gt;https://github.com/leinadred/py_cp-updatable-objects&lt;/A&gt;&amp;nbsp;from line 59 (&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;res_repo&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;=....)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Jan 2023 12:02:43 GMT</pubDate>
    <dc:creator>Nüüül</dc:creator>
    <dc:date>2023-01-24T12:02:43Z</dc:date>
    <item>
      <title>python api script</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/python-api-script/m-p/168668#M7429</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have installed latest version of checkpoint mgmt R81.20 in a test environment and want to use the latest API: &lt;A href="https://sc1.checkpoint.com/documents/latest/APIs/#tips_best_practices~v1.9%20" target="_blank" rel="noopener"&gt;https://sc1.checkpoint.com/documents/latest/APIs/#introduction~v1.9%20&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I want to automate some tasks using python script from my desktop pc, not run the script directly on checkpoint gateway. I tried with checkpoints official python SDK: &lt;A href="https://github.com/CheckPointSW/cp_mgmt_api_python_sdk" target="_blank" rel="noopener"&gt;https://github.com/CheckPointSW/cp_mgmt_api_python_sdk&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But the API commands for the python SDK do not match with the latest Management API Reference v1.9 from checkpoint?&lt;/P&gt;&lt;P&gt;For example from python sdk example:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;add_rule_response&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;client&lt;/SPAN&gt;.&lt;SPAN class=""&gt;api_call&lt;/SPAN&gt;(&lt;SPAN class=""&gt;"&lt;STRONG&gt;add-access-rule&lt;/STRONG&gt;"&lt;/SPAN&gt;,&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;{&lt;SPAN class=""&gt;"name"&lt;/SPAN&gt;: &lt;SPAN class=""&gt;rule_name&lt;/SPAN&gt;, &lt;SPAN class=""&gt;"layer"&lt;/SPAN&gt;: &lt;SPAN class=""&gt;"Network"&lt;/SPAN&gt;, &lt;SPAN class=""&gt;"position"&lt;/SPAN&gt;: &lt;SPAN class=""&gt;"top"&lt;/SPAN&gt;})&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and example from Management API Reference v1.9:&lt;/P&gt;&lt;P class=""&gt;Command&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;add access-rule&lt;/STRONG&gt; layer "Network" position 1 name "Rule 1" service.1 "SMTP" service.2 "AOL" vpn "MyIntranet"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And also I do not find in the documentation for the python SDK all the avaible commands and how to handle session etc. Since the commands are not identical I wonder how to proceed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please advice and help me get started.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If i want to use latest Management API Reference v1.9, should i instead use web api in the python script instead of the python sdk?&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jan 2023 13:55:10 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/python-api-script/m-p/168668#M7429</guid>
      <dc:creator>Roberts12</dc:creator>
      <dc:date>2023-01-22T13:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: python api script</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/python-api-script/m-p/168715#M7430</link>
      <description>&lt;P data-unlink="true"&gt;Hi, I would start with the REST API and use something simple like Python requests to manage the connections. I've worked on several projects recently and didn't need the full SDK. Depending on what you're trying to work on, you might find that something like Ansible is more convenient for you. There are some examples of both approaches here &lt;A href="https://developer.checkpoint.com" target="_blank" rel="noopener"&gt;https://developer.checkpoint.com&lt;/A&gt;&amp;nbsp;or I've used a simple wrapper package here&amp;nbsp;&lt;A href="https://github.com/chkp-stuartgreen/policy-automation-poc/blob/main/packages/simplecpapi.py" target="_blank"&gt;https://github.com/chkp-stuartgreen/policy-automation-poc/blob/main/packages/simplecpapi.py&lt;/A&gt;&amp;nbsp;where I didn't want the full SDK, but didn't want to repeat lots of code either.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 10:30:01 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/python-api-script/m-p/168715#M7430</guid>
      <dc:creator>StuartGreen</dc:creator>
      <dc:date>2023-01-23T10:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: python api script</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/python-api-script/m-p/168870#M7447</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;i believe you mixed up the different ways to leverage the api.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"add-access-rule" uses web service&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"add access-rule" uses the mgmt cli (which is calling API too but is called via cli at management server)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;you can switch between them in the documentation - see attached screenshot.&lt;BR /&gt;When you are logging in into the API, a session id is generated and sent back to you as response. This session id you will need to add at the following request´s header.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example for callin web API with SDK:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with APIClient(client_args) as client:
    # If Error occurs due to fingerprint mismatch
    if client.check_fingerprint() is False:
        #output_text.update({"Message":"Could not get the server's fingerprint - Check connectivity with the server."})
        print("UNKNOWN! Logging into SMS not successful! Please troubleshoot/debug script! "+str(output_text))
        raise SystemExit()
    # login to server:
    login_res = client.login(api_user, api_pwd)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so:&lt;/P&gt;&lt;P&gt;documentation is acurate - when using the correct way to call the api&lt;/P&gt;&lt;P&gt;SDK simplifies things like session handling - to understand all the things, you can manually write https requests towards the API with correct headers and so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in case you need help, feel free to reach out&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 09:37:24 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/python-api-script/m-p/168870#M7447</guid>
      <dc:creator>Nüüül</dc:creator>
      <dc:date>2023-01-24T09:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: python api script</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/python-api-script/m-p/168903#M7448</link>
      <description>&lt;P&gt;Thank you for the explanation! if you have more examples to share it would be appreciated.&lt;BR /&gt;I can run the example scripts from the github repo, but when I extend the script with more functions and more API calls I get this error message:&amp;nbsp;&lt;BR /&gt;Failed to add the access-rule: '1', Error:&lt;BR /&gt;code: generic_err_wrong_session_id&lt;BR /&gt;message: Wrong session id [XwGUCgAvdFDB2_8vTN2KBXV-XCynk4Zp12Q]. Session may be expired. Please check session id and resend the request&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 11:50:38 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/python-api-script/m-p/168903#M7448</guid>
      <dc:creator>Roberts12</dc:creator>
      <dc:date>2023-01-24T11:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: python api script</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/python-api-script/m-p/168907#M7449</link>
      <description>&lt;P&gt;I wrote some scripts leveraging the SDK - like:&amp;nbsp;&lt;A href="https://github.com/leinadred/CP_IPS-Update-Monitoring4Nagios" target="_blank" rel="noopener"&gt;https://github.com/leinadred/CP_IPS-Update-Monitoring4Nagios&amp;nbsp;&lt;/A&gt;or &lt;A href="https://github.com/leinadred/py_cp-updatable-objects" target="_blank" rel="noopener"&gt;https://github.com/leinadred/py_cp-updatable-objects&lt;/A&gt;&lt;/P&gt;&lt;P&gt;difficult to say, without being able to see your script. but i think you went out of the "with" procedure, so SDK logged you out. As API is "opened" like a file, with is closing it (and logs off the connection) when leaving the file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So your "working procedures" will have to be inside of the "opened file"&lt;/P&gt;&lt;P&gt;in&amp;nbsp;&lt;A href="https://github.com/leinadred/py_cp-updatable-objects" target="_blank" rel="noopener"&gt;https://github.com/leinadred/py_cp-updatable-objects&lt;/A&gt;&amp;nbsp;from line 59 (&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;res_repo&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;=....)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 12:02:43 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/python-api-script/m-p/168907#M7449</guid>
      <dc:creator>Nüüül</dc:creator>
      <dc:date>2023-01-24T12:02:43Z</dc:date>
    </item>
  </channel>
</rss>

