<?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 Creating Network Objects via API in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Creating-Network-Objects-via-API/m-p/54961#M3548</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I have a requirement to create network objects via API (mgmt_cli or smartconsole CLI) but the catch is:&lt;/P&gt;&lt;P&gt;API needs to create the object with the provided name and IP address, etc only if no object exists with that IP address.&lt;/P&gt;&lt;P&gt;API needs to edit the name, comments fields if an object exists for a given IP address.&lt;/P&gt;&lt;P&gt;Both needs to be part of the same script (may be like a if,else script).&lt;/P&gt;&lt;P&gt;Can someone shed some light on this?&lt;/P&gt;&lt;P&gt;Thanks in Advance!&lt;/P&gt;</description>
    <pubDate>Mon, 03 Jun 2019 18:47:50 GMT</pubDate>
    <dc:creator>venkata_marutur</dc:creator>
    <dc:date>2019-06-03T18:47:50Z</dc:date>
    <item>
      <title>Creating Network Objects via API</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Creating-Network-Objects-via-API/m-p/54961#M3548</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I have a requirement to create network objects via API (mgmt_cli or smartconsole CLI) but the catch is:&lt;/P&gt;&lt;P&gt;API needs to create the object with the provided name and IP address, etc only if no object exists with that IP address.&lt;/P&gt;&lt;P&gt;API needs to edit the name, comments fields if an object exists for a given IP address.&lt;/P&gt;&lt;P&gt;Both needs to be part of the same script (may be like a if,else script).&lt;/P&gt;&lt;P&gt;Can someone shed some light on this?&lt;/P&gt;&lt;P&gt;Thanks in Advance!&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 18:47:50 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Creating-Network-Objects-via-API/m-p/54961#M3548</guid>
      <dc:creator>venkata_marutur</dc:creator>
      <dc:date>2019-06-03T18:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Network Objects via API</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Creating-Network-Objects-via-API/m-p/54966#M3549</link>
      <description>&lt;P&gt;First off, unless you include set-if-exists true as part of your API call, the API will not allow you to create an object if something with the same IP exists--you'll get an error like:&lt;/P&gt;
&lt;PRE style="padding-left: 30px;"&gt;[Expert@mgmt:0]# &lt;STRONG&gt;mgmt_cli -r true add host name foobar ipv4-address 192.168.1.1&lt;/STRONG&gt;&lt;BR /&gt;code: "err_validation_failed"&lt;BR /&gt;message: "Validation failed with 1 warning"&lt;BR /&gt;warnings:&lt;BR /&gt;- message: "Multiple objects have the same IP address 192.168.1.1"&lt;/PRE&gt;
&lt;P&gt;The trick is figuring out what object has that IP.&lt;BR /&gt;Fortunately, there's an API call for that:&lt;/P&gt;
&lt;PRE style="padding-left: 30px;"&gt;[Expert@mgmt:0]# &lt;STRONG&gt;mgmt_cli -r true show objects filter 192.168.1.1 ip-only true type host&lt;/STRONG&gt;&lt;BR /&gt;from: 1&lt;BR /&gt;to: 1&lt;BR /&gt;total: 1&lt;BR /&gt;objects:&lt;BR /&gt;- uid: "846051cb-a16a-4c4b-acfc-664217fc8ee6"&lt;BR /&gt;name: "barfoo"&lt;BR /&gt;type: "host"&lt;BR /&gt;domain:&lt;BR /&gt;uid: "41e821a0-3720-11e3-aa6e-0800200c9fde"&lt;BR /&gt;name: "SMC User"&lt;BR /&gt;domain-type: "domain"&lt;BR /&gt;ipv4-address: "192.168.1.1"&lt;/PRE&gt;
&lt;P&gt;Now, you can reference the object by UID and change the name/comment:&lt;/P&gt;
&lt;PRE&gt;[Expert@mgmt:0]# &lt;STRONG&gt;mgmt_cli -r true set host uid 846051cb-a16a-4c4b-acfc-664217fc8ee6 new-name foobar \&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;                          comments "This is my comment"&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;---------------------------------------------&lt;BR /&gt;Time: [13:56:11] 3/6/2019&lt;BR /&gt;---------------------------------------------&lt;BR /&gt;"Publish operation" succeeded (100%)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;How you script the above is up to you, but that's the gist of it.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 21:07:43 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Creating-Network-Objects-via-API/m-p/54966#M3549</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2019-06-03T21:07:43Z</dc:date>
    </item>
  </channel>
</rss>

