<?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: How to Create and Populate a Virtual Group Using Python and the Harmony Endpoint API in Endpoint</title>
    <link>https://community.checkpoint.com/t5/Endpoint/How-to-Create-and-Populate-a-Virtual-Group-Using-Python-and-the/m-p/240859#M10198</link>
    <description>&lt;P&gt;Thanks for sharing!&lt;/P&gt;</description>
    <pubDate>Mon, 10 Feb 2025 19:18:29 GMT</pubDate>
    <dc:creator>PhoneBoy</dc:creator>
    <dc:date>2025-02-10T19:18:29Z</dc:date>
    <item>
      <title>How to Create and Populate a Virtual Group Using Python and the Harmony Endpoint API</title>
      <link>https://community.checkpoint.com/t5/Endpoint/How-to-Create-and-Populate-a-Virtual-Group-Using-Python-and-the/m-p/240429#M10178</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Introduction&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;In this article, I will share a Python script that allows you to create and populate a Virtual Group using the Harmony Endpoint API. I will explain the necessary steps to obtain the CLIENT_ID and ACCESS_KEY and how to use them to authenticate and consume the API.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 1: Authentication&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Thanks to Facundo García Parolari (Novared), I understood which options to select to generate the CLIENT_ID and ACCESS_KEY. Once obtained, these credentials will be used to generate a token that is passed as a parameter to access the API.&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="harmony.png" style="width: 405px;"&gt;&lt;img src="https://community.checkpoint.com/t5/image/serverpage/image-id/29529i127581D00045809E/image-dimensions/405x385?v=v2" width="405" height="385" role="button" title="harmony.png" alt="harmony.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Which in this case is "Endpoint", in my case it was not clear to me among so many options.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 2: Required URLs&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;It is important to consider your subscription region when defining the URLs:&lt;/P&gt;&lt;P&gt;AUTH_URL = "&lt;A href="https://cloudinfra-gw-us.portal.checkpoint.com/auth/external" target="_blank" rel="noopener"&gt;https://cloudinfra-gw-us.portal.checkpoint.com/auth/external&lt;/A&gt;"&amp;nbsp;&lt;/P&gt;&lt;P&gt;LOGIN_URL = "&lt;A href="https://cloudinfra-gw.portal.checkpoint.com/app/endpoint-web-mgmt/harmony/endpoint/api/v1/session/login/cloud" target="_blank" rel="noopener"&gt;https://cloudinfra-gw.portal.checkpoint.com/app/endpoint-web-mgmt/harmony/endpoint/api/v1/session/login/cloud&lt;/A&gt;"&amp;nbsp;&lt;/P&gt;&lt;P&gt;CREATE_VIRTUAL_GROUP_URL = "&lt;A href="https://cloudinfra-gw.portal.checkpoint.com/app/endpoint-web-mgmt/harmony/endpoint/api/v1/organization/virtual-group/create" target="_blank" rel="noopener"&gt;https://cloudinfra-gw.portal.checkpoint.com/app/endpoint-web-mgmt/harmony/endpoint/api/v1/organization/virtual-group/create&lt;/A&gt;"&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note:&lt;/STRONG&gt; The region cloudinfra-gw-us is for this specific configuration.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 3: Obtain Computer IDs&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;To populate the Virtual Group, it is necessary to obtain the computer IDs. I search for objects (e.g., "Computer"), store them in an array, and then pass them as a parameter when creating the group.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 4: Create and Populate the Virtual Group&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The following code demonstrates how to perform this task:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H6&gt;&lt;FONT size="2" color="#FF0000"&gt;import requests&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;import json&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;def get_token(client_id, access_key):&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; payload = {&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "clientId": client_id,&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "accessKey": access_key&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; response = requests.post(AUTH_URL, json=payload)&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return response.json().get("token")&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;def create_virtual_group(token, api_token, group_name, description, computer_ids):&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; headers = {&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Authorization": f"Bearer {token}",&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "X-API-Key": api_token,&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Content-Type": "application/json"&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; payload = {&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "name": group_name,&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "description": description,&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "computerIds": computer_ids&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; response = requests.post(CREATE_VIRTUAL_GROUP_URL, headers=headers, json=payload)&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return response.json()&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;# Get the authentication token&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;client_id = "YOUR_CLIENT_ID"&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;access_key = "YOUR_ACCESS_KEY"&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;token = get_token(client_id, access_key)&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;# Group data&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;group_name = "Group1"&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;description = "Test group"&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;computer_ids = [&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "c8929cd6-c69e-47d7-b8d8-f9b9dcf7a2a1",&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "f2d01a1f-efd1-495c-9abf-f62edcbdfb26"&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;]&amp;nbsp; # Replace with valid IDs&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;# Create the virtual group&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;api_token = "YOUR_API_TOKEN"&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;response = create_virtual_group(token, api_token, group_name, description, computer_ids)&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" color="#FF0000"&gt;print("API Response:", response)&amp;nbsp;&lt;/FONT&gt;&lt;/H6&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Final Explanation&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The script is designed to:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Authenticate using the CLIENT_ID and ACCESS_KEY.&lt;/LI&gt;&lt;LI&gt;Obtain a session token.&lt;/LI&gt;&lt;LI&gt;Create a Virtual Group using the specified computer IDs.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I hope this guide helps you automate the management of Virtual Groups within your Harmony Endpoint environment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2025 00:16:15 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Endpoint/How-to-Create-and-Populate-a-Virtual-Group-Using-Python-and-the/m-p/240429#M10178</guid>
      <dc:creator>AOBELAR</dc:creator>
      <dc:date>2025-02-05T00:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create and Populate a Virtual Group Using Python and the Harmony Endpoint API</title>
      <link>https://community.checkpoint.com/t5/Endpoint/How-to-Create-and-Populate-a-Virtual-Group-Using-Python-and-the/m-p/240859#M10198</link>
      <description>&lt;P&gt;Thanks for sharing!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2025 19:18:29 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Endpoint/How-to-Create-and-Populate-a-Virtual-Group-Using-Python-and-the/m-p/240859#M10198</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2025-02-10T19:18:29Z</dc:date>
    </item>
  </channel>
</rss>

