<?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 MGMT_API delete all objects with TAGs &amp;quot;TEST&amp;quot; in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134251#M6433</link>
    <description>&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created almost 20k objects (hosts, networks,domains,...) with tags "TEST"&lt;/P&gt;&lt;P&gt;I would like to delete them easly.&lt;/P&gt;&lt;P&gt;Is there any commands line to use for deleting all objects relating to tags "TEST" ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help.&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;/P&gt;&lt;P&gt;Medm&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Nov 2021 12:01:39 GMT</pubDate>
    <dc:creator>MedM</dc:creator>
    <dc:date>2021-11-17T12:01:39Z</dc:date>
    <item>
      <title>MGMT_API delete all objects with TAGs "TEST"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134251#M6433</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created almost 20k objects (hosts, networks,domains,...) with tags "TEST"&lt;/P&gt;&lt;P&gt;I would like to delete them easly.&lt;/P&gt;&lt;P&gt;Is there any commands line to use for deleting all objects relating to tags "TEST" ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help.&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;/P&gt;&lt;P&gt;Medm&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 12:01:39 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134251#M6433</guid>
      <dc:creator>MedM</dc:creator>
      <dc:date>2021-11-17T12:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: MGMT_API delete all objects with TAGs "TEST"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134279#M6434</link>
      <description>&lt;P&gt;Just use the following command and the Tag should be completely deleted from all objects:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;mgmt_cli delete tag&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://sc1.checkpoint.com/documents/latest/APIs/index.html#cli/delete-tag~v1.8%20" target="_blank"&gt;https://sc1.checkpoint.com/documents/latest/APIs/index.html#cli/delete-tag~v1.8%20&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use Tag name or UID&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 15:52:53 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134279#M6434</guid>
      <dc:creator>Tal_Paz-Fridman</dc:creator>
      <dc:date>2021-11-17T15:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: MGMT_API delete all objects with TAGs "TEST"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134286#M6435</link>
      <description>&lt;DIV class=""&gt;Dear Tal_Paz-Fridman&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;Thank you for your reply.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;The goal is to delete all the created 20k objects with TAG "TEST".&lt;/DIV&gt;&lt;DIV class=""&gt;In fact, I am working with SmartMove scripts and would like to run the scripts again after analysing and resolving errors found on failed_objects.txt file.&lt;/DIV&gt;&lt;DIV class=""&gt;From CMA, I selected all objects with TAG TEST but when I tried to delete them but I get disconnected after almost 2 minutes.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;The proposed command "mgmt_cli delete tag" will delete all objects with Tag "TEST" or only the TAG "TEST" from objects ?&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;Thanks again for you help.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;Kind Regards,&lt;/DIV&gt;&lt;DIV class=""&gt;Medm&lt;/DIV&gt;</description>
      <pubDate>Wed, 17 Nov 2021 16:20:14 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134286#M6435</guid>
      <dc:creator>MedM</dc:creator>
      <dc:date>2021-11-17T16:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: MGMT_API delete all objects with TAGs "TEST"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134306#M6437</link>
      <description>&lt;P&gt;I think that will only remove the tag.&lt;BR /&gt;To remove all objects with said tag, you’ll probably have to write a script to iterate over all the objects that have said tag and remove said object.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 21:58:02 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134306#M6437</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2021-11-17T21:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: MGMT_API delete all objects with TAGs "TEST"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134665#M6447</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I refered to your old similar solution found on the link below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;A href="https://community.checkpoint.com/t5/API-CLI-Discussion/mgmt-cli-to-delete-all-objects-matching-a-pattern/td-p/75217" target="_blank"&gt;https://community.checkpoint.com/t5/API-CLI-Discussion/mgmt-cli-to-delete-all-objects-matching-a-pattern/td-p/75217&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I tried using this command below but I get the error&lt;/P&gt;&lt;P&gt;mgmt_cli -s id.txt delete objects-batch $(mgmt_cli -s id.txt -f json show objects filter "TEST" limit 500 | jq '.objects[].name' | cat -n | sed -r 's/^\s+([0-9]+)/objects.1.list.\1.name/' | tr '\n' ' ')&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;code: "generic_err_command_not_found"&lt;BR /&gt;message: "Requested API command: [delete-objects-batch] not found"&lt;/P&gt;&lt;P&gt;I am working with API v1.1 (api-server-version: "1.1")&lt;/P&gt;&lt;P&gt;Any help please ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;MedM&lt;/P&gt;</description>
      <pubDate>Mon, 22 Nov 2021 14:20:38 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134665#M6447</guid>
      <dc:creator>MedM</dc:creator>
      <dc:date>2021-11-22T14:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: MGMT_API delete all objects with TAGs "TEST"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134675#M6448</link>
      <description>&lt;P&gt;That API endpoint is not available in R80.10 (API version 1.1).&lt;BR /&gt;You will need to upgrade your management server to a version that supports it (R80.40, API v1.6).&amp;nbsp;&lt;BR /&gt;&lt;A href="https://sc1.checkpoint.com/documents/latest/APIs/index.html#cli/delete-objects-batch~v1.6%20" target="_blank"&gt;https://sc1.checkpoint.com/documents/latest/APIs/index.html#cli/delete-objects-batch~v1.6%20&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Nov 2021 16:33:52 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134675#M6448</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2021-11-22T16:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: MGMT_API delete all objects with TAGs "TEST"</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134681#M6449</link>
      <description>&lt;P&gt;One concern with this method is it could catch objects with "TEST" in the name.&lt;/P&gt;
&lt;P&gt;I don't know of a way to go from a tag to the objects tagged with it. "where-used" doesn't work for tags:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;[Expert@DallasSA]# mgmt_cli -f json -r true show host name staxBerlinDevWebVip | jq '{uid:.uid,name:.name,tags:[.tags[]|{uid:.uid,name:.name}]}'
{
  "uid": "70b131cb-e099-4b81-9345-53e5f4752b98",
  "name": "staxBerlinDevWebVip",
  "tags": [
    {
      "uid": "962a5a68-29a9-4407-921a-b774890b0a39",
      "name": "Development"
    },
    {
      "uid": "0a4b231c-bfad-4b37-8b50-b21a0c0f3f4a",
      "name": "Berlin"
    },
    {
      "uid": "63599767-883e-47aa-a04c-fc7d30b16a84",
      "name": "Stax"
    }
  ]
}
[Expert@DallasSA]# mgmt_cli -f json -r true where-used uid 962a5a68-29a9-4407-921a-b774890b0a39
{
  "code" : "generic_err_object_not_found",
  "message" : "Requested object [962a5a68-29a9-4407-921a-b774890b0a39] not found"
}&lt;/LI-CODE&gt;
&lt;P&gt;I think the only guaranteed option is to enumerate all of your objects, find the ones with the tag you care about, then send them to mgmt_cli delete-&amp;lt;type&amp;gt;. Something like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;TagName="Development"

mgmt_cli -r true login &amp;gt; session.txt
echo "" &amp;gt; toRemove.txt
ObjectCount=$(mgmt_cli -f json -s session.txt show objects limit 1 details-level uid | jq '.total')
for GetOffset in $(seq 1 500 "${ObjectCount}"); do
mgmt_cli -f json -s session.txt show hosts limit 500 offset "${GetOffset}" details-level full | jq -c '.objects[]|{uid:.uid,type:.type,tag:.tags[]|.name}' | grep "\"tag\":\"${TagName}\"" &amp;gt;&amp;gt; toRemove.txt
done

PublishEvery=100
ChangeCount=1
function deleteObject {
mgmt_cli -s session.txt delete-"$1" uid "$2"
((ChangeCount+=1))
if [ ${ChangeCount} -gt ${PublishEvery} ]; then
mgmt_cli -s session.txt publish
ChangeCount=1
fi
}

while read ObjectToRemove; do
deleteObject "$(echo $ObjectToRemove | cut -d '"' -f 8)" "$(echo $ObjectToRemove | cut -d '"' -f 4)"
done &amp;lt; toRemove.txt

mgmt_cli -s session.txt publish
mgmt_cli -s session.txt logout
rm toRemove.txt
rm session.txt&lt;/LI-CODE&gt;
&lt;P&gt;Note that I have not tested this! It should work, though. If you only run the top section (everything before "PublishEvery=100"), it will spit out a file with the objects it would remove. That would let you preview what the bottom section would do.&lt;/P&gt;
&lt;P&gt;Make&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;and test&lt;/STRONG&gt;&lt;/EM&gt; a backup before running code you get like this from somebody you don't know.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Nov 2021 17:29:38 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/MGMT-API-delete-all-objects-with-TAGs-quot-TEST-quot/m-p/134681#M6449</guid>
      <dc:creator>Bob_Zimmerman</dc:creator>
      <dc:date>2021-11-22T17:29:38Z</dc:date>
    </item>
  </channel>
</rss>

